This is the mail archive of the gcc@gcc.gnu.org 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 <ian@wasabisystems.com> writes:

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

 Ian> It is somewhat better in the current sources:

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

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

Probably.  

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 ..."

	paul


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