This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ typedef redefinitions and templates



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]