C++ typedef redefinitions and templates
Jens Maurer
jmaurer@menuett.rhein-main.de
Fri Feb 11 02:01:00 GMT 2000
I may have found a bug in g++. Versions tested:
gcc version 2.95.2 19991024 (release)
gcc version 2.96 20000204 (experimental)
In contrast to 2.95.2, the newer CVS checkout is happy with
this code:
struct A {
typedef int T;
typedef int T;
};
However, involving templates in the typedef's fails even with
the newer CVS checkout:
template<class T>
struct A {
typedef int X;
typedef T X;
};
The error message is:
double-typedef-template.cc:5: declaration of `typedef T A<T>::X'
double-typedef-template.cc:4: conflicts with previous declaration `typedef int A<T>::X'
This is in violation of ISO C++ section 7.1.3/2 [dcl.typedef]. In this case,
it is not known until template instantiation time whether the code is legal
or not.
Preliminary analysis: The error message is generated by
gcc/cp/decl.c:add_binding(). For typedef's involving template args, this
is probably the wrong place for the check. Instead, gcc/cp/pt.c:tsubst()
might need to check for duplicate non-identical typedef's after the
template args substitution.
Jens Maurer
More information about the Gcc-bugs
mailing list