First reported in http://gcc.gnu.org/ml/gcc/2004-06/msg00690.html: 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 What should be reported instead is that the correct syntax for a destructor is Test<Type>::~Test(void) , i.e., omit the extra <Test>
Confirmed.
The invalid constructor is now rejected in 3.5.0 thanks to a recent patch of mine: 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 Notice that this is not a regression, so I cannot backport the patch to the 3.4 serie. What is left here is to emit a similar error message for the destructor, instead of the crypting (and wrong) diagnostic we get: 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
Actually, it turns out that it's unclear whether the standard allows naming the destructor as a template. The lookup rules are complex and confusing, there are a couple of defect reports (DR 399 and DR 244 for instance) and it is still unclear. My general understanding is that the committee is going to allow more complex forms of destructor naming rather than limiting it. I'm testing a patch which lets GCC accepts the templated form without an error.
Well, 3.3 accepts the very same destructor declaration so this is a regression. I'm submitting the patch soon.
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2004-06/msg00888.html
Subject: Bug 15947 CVSROOT: /cvs/gcc Module name: gcc Changes by: giovannibajo@gcc.gnu.org 2004-06-15 00:24:47 Modified files: gcc/cp : ChangeLog parser.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/parse: dtor4.C Log message: PR c++/15947 * parser.c (cp_parser_template_name): Ctors/dtors never need a template keyword to disambiguate. PR c++/15947 * g++.dg/parse/dtor4.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4095&r2=1.4096 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.204&r2=1.205 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3857&r2=1.3858 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/dtor4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 15947 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: giovannibajo@gcc.gnu.org 2004-06-15 00:29:37 Modified files: gcc/cp : ChangeLog parser.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/parse: dtor4.C Log message: PR c++/15947 * parser.c (cp_parser_template_name): Ctors/dtors never need a template keyword to disambiguate. PR c++/15947 * g++.dg/parse/dtor4.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.123&r2=1.3892.2.124 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.33&r2=1.157.2.34 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.207&r2=1.3389.2.208 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/dtor4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
Fixed for GCC 3.4.1 and GCC 3.5.0. Thank you for your report!