This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Puzzling error message about templates (gcc 3.4.0)
- From: Paul Koning <pkoning at equallogic dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 10 Jun 2004 16:20:21 -0400
- Subject: Re: Puzzling error message about templates (gcc 3.4.0)
- References: <16584.45429.493584.876001@gargle.gargle.HOWL>
Following up on my own message:
> From: Paul Koning <pkoning@equallogic.com>
> To: gcc@gcc.gnu.org
> Date: Thu, 10 Jun 2004 15:07:33 -0400
> Subject: Puzzling error message about templates (gcc 3.4.0)
>
> GCC 3.4 objects to this (GCC 3.3 does not):
>
> template <class Type> class Test
> {
> public:
> Test(void);
> ~Test(void);
> static bool probe(void *addr);
> };
>
> template <class Type> inline bool Test<Type>::probe(void *addr)
> {}
>
> template <class Type> inline Test<Type>::Test<Type>(void)
> {}
>
> template <class Type> inline Test<Type>::~Test<Type>(void)
> {}
>
> The error messages is:
>
> foo.cc:15: error: non-template `Test' used as template
> foo.cc:15: error: (use `Test<Type>::template Test' to indicate that it is a template)
> foo.cc:15: error: expected class-name at end of input
> foo.cc:15: error: expected init-declarator at end of input
> foo.cc:15: error: expected `;' at end of input
>
> I can't figure out what the suggestion is trying to suggest (in other
> words, I can't tell what the proposed replacement source would look
> like).
>
> But what's really puzzling is that it only complains about the
> destructor, even though the other two methods have the identical
> pattern. Parser bug?
Not a parser bug, but a very confusing message.
The correct syntax for template class constructors/destructors is (as
far as I can fathom from my textbooks)
template <class Type> inline Test<Type>::Test(void) {}
template <class Type> inline Test<Type>::~Test(void) {}
without the extra <Type> just before the (void). The other form was
accepted by the old parser, and it's a natural mistake to make because
constructor names are "the name of the class" -- and one might figure
that "Test<Type>" is that name.
Anyway, the message doesn't say that. It's also doubly confusing
because the (presumably) incorrect constructor syntax is silently
accepted while the destructor causes the error messages.
paul