Internal compiler error
Martin v. Loewis
martin@mira.isdn.cs.tu-berlin.de
Sun Oct 24 01:30:00 GMT 1999
> I have seen several examples of deriving a class from a base class
> that is a template class, and passing the derived class as the
> template argument of the base class (Coplien, Barton/Nackman).
That is not the problem, g++ accepts this construct.
> Of course the examples are 5+ years old. Are those examples no longer
> valid?
The problem is the specific member declaration:
typename derivedClass::aStruct * aStructPtr;
which is not accepted. In a previous message, I wrote that I thought
the construct was ok and that there was a bug in gcc; after thinking
about it again, I now believe that gcc is right.
The question is when exactly the template is instantiated. Clearly,
the instantiation must be complete before the template can be used as
a base class, since the base class must be a complete class. This is
necessary as the parsing of the derived class might refer to names in
the base class.
The point-of-instantiation is defined in 14.6.4.1/3:
# Otherwise, the point of instantiation for such a specialization
# immediately precedes the namespace scope declaration or definition
# that refers to the specialization.
So the template is instantiated immediately before the derived class
is defined (which is immediately after the point-of-declaration of the
derived class).
Therefore, inside the template instantiation, the template parameter
is an incomplete type. typename derivedClass::aStruct is an error; the
declaration of A::aStruct has not been seen, yet. Hence the error
message.
Hope this clarifies it,
Martin
More information about the Gcc-bugs
mailing list