This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Internal compiler error
- To: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Subject: Re: Internal compiler error
- From: Mark Crosland <mjc at c1000907-b dot sttls1 dot wa dot home dot com>
- Date: Sun, 24 Oct 1999 10:09:43 -0700 (PDT)
- cc: gcc-bugs at gcc dot gnu dot org
A couple of observations that muddy the waters a little for me...
- If the typename qualifier is removed from the aStructPtr definition,
gcc(egcs 1.1.2) suggests trying typename.
- I have modified my example so the typename construct is accepted by
gcc (egcs-1.1.2) inside a function within the B template class. It looks
like the statement "typename derivedClass::aStruct * aStructPtr;" is being
handled differently depending on whether it is a member variable or a
function variable (?).
Here is the modified example.
Thanks,
Mark
//////////////////////////////////////////////////////////////////
#include <stdio.h>
template <class derivedClass> class B {
public:
B(){}
~B(){}
bOperation1()
{
typename derivedClass::aStruct aStructPtr;
aStructPtr.x = -1;
printf("aStructPtr.x:%d\n",aStructPtr.x);
aPtr->aOperation();
}
protected:
int x;
derivedClass * aPtr;
//typename derivedClass::aStruct * aStructPtr;
};
class A : public B <A> {
protected:
typedef struct { int x; } aStruct;
public:
A(){}
~A(){}
void aOperation()
{
aStruct as;
as.x = 1;
printf("as.x:%d\n",as.x);
}
};
int main()
{
A anA;
anA.bOperation1();
}
///////////////////////////////////////////////////////////////////
On Sun, 24 Oct 1999, Martin v. Loewis wrote:
>
> 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
>