[Bug c++/43117] New: Accepts invalid typedef
bangerth at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Feb 19 00:56:00 GMT 2010
This is the remaining part of PR 9990 that concerns interpretation of
the core language rules. Consider this code snippet:
-----------------------------
struct B { typedef int type; };
template <typename T> struct D : B {
typedef typename D::type type;
};
D<char> cc;
D<char>::type tcc;
-----------------------------
All GCC versions accept this. The question is whether the typedef in D is
well-formed: does D::type refer to the typedef in the base class, or to the
typedef we are currently declaring?
The issue is confusing because if D is not a template, like here:
-----------------------------
struct B { typedef int type; };
struct D : B {
typedef typename D::type type;
};
D<char> cc;
D<char>::type tcc;
-----------------------------
then apparently the code is ill-formed:
tmp> c++ -c a.cc
a.cc:3: error: using 'typename' outside of template
a.cc:6: error: 'D' is not a template
a.cc:7: error: 'D' is not a template
a.cc:7: error: expected initializer before 'tcc'
It is at best confusing that templates and non-templates should behave
differently in this regard.
I don't claim to know whether the current behavior is correct. Putting
this issue into a separate PR cleans up PR 9990, however.
Best
W.
--
Summary: Accepts invalid typedef
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bangerth at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43117
More information about the Gcc-bugs
mailing list