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)

>>>>> "Ian" == Ian Lance Taylor <> writes:

 Ian> Paul Koning <> 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.

 Ian> It is somewhat better in the current sources:

 Ian> error: invalid use of constructor as a template
 Ian> note: use `Test<Type>::Test' instead of
 Ian> `Test<Type>::Test<Type>' to name the constructor in a qualified
 Ian> name error: non-template `Test' used as template
 Ian> error: (use `Test<Type>::template Test' to indicate
 Ian> that it is a template) error: expected class-name at
 Ian> end of input error: expected init-declarator at end
 Ian> of input error: expected `;' at end of input

 Ian> (Shouldn't the fourth line by note instead of error?)


That new message for line 12 helps a lot.  The surprise is that the
parser doesn't recognize line 15 as an analogous mistake, i.e.,
"Invalid use of destructor as a template.... use Test<Type>::~Test
instead of ..."


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