Bug 15947 - [3.4/4.0 Regression] Puzzling error message for wrong destructor declaration in template class
Summary: [3.4/4.0 Regression] Puzzling error message for wrong destructor declaration ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 critical
Target Milestone: 3.4.1
Assignee: Giovanni Bajo
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2004-06-11 17:22 UTC by Paul Koning
Modified: 2004-10-30 21:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3
Known to fail: 3.4.0 4.0.0
Last reconfirmed: 2004-06-11 17:28:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Koning 2004-06-11 17:22:13 UTC
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>
Comment 1 Andrew Pinski 2004-06-11 17:28:26 UTC
Confirmed.
Comment 2 Giovanni Bajo 2004-06-12 12:07:49 UTC
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
Comment 3 Giovanni Bajo 2004-06-12 12:22:59 UTC
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. 
Comment 4 Giovanni Bajo 2004-06-13 02:20:45 UTC
Well, 3.3 accepts the very same destructor declaration so this is a regression.
I'm submitting the patch soon.
Comment 5 Giovanni Bajo 2004-06-13 03:28:12 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2004-06/msg00888.html
Comment 6 GCC Commits 2004-06-15 00:24:50 UTC
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

Comment 7 GCC Commits 2004-06-15 00:29:40 UTC
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

Comment 8 Giovanni Bajo 2004-06-15 00:30:07 UTC
Fixed for GCC 3.4.1 and GCC 3.5.0. Thank you for your report!