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)
Paul Koning <pkoning@equallogic.com> writes:
> 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.
It is somewhat better in the current sources:
foo.cc:12: error: invalid use of constructor as a template
foo.cc:12: note: use `Test<Type>::Test' instead of `Test<Type>::Test<Type>' to name the constructor in a qualified name
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
(Shouldn't the fourth line by note instead of error?)
Ian