This is the mail archive of the 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]
Other format: [Raw text]

Re: Puzzling error message about templates (gcc 3.4.0)

Following up on my own message:

> From: Paul Koning <>
> To:
> 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:
> error: non-template `Test' used as template
> error: (use `Test<Type>::template Test' to indicate that it is a template)
> error: expected class-name at end of input
> error: expected init-declarator at end of input
> 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.


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