This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/19980: ICE on invalid template declaration
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 19 Feb 2005 22:02:44 +0100 (CET)
- Subject: [patch] Fix PR c++/19980: ICE on invalid template declaration
On mainline we ICE on the following invalid code snippet:
=============================
int foo;
template<int> void foo() {}
=============================
The error message reads:
bug.cc:2: error: 'template<int <anonymous> > void foo()' redeclared
as different kind of symbol
bug.cc:1: error: previous declaration of 'int foo'
Internal compiler error: Error reporting routines re-entered.
Please submit a full bug report, [etc.]
This is due to a problem in start_preparsed_function: When processing
the template declaration the call "push_template_decl (decl1);"
returns an error_mark_node, since "foo" is already declared as "int".
Since the error_mark_node is not handled, things go downhill from here.
The following patch fixes the problem by ignoring the result of
push_template_decl if an error_mark_node is returned.
Bootstrapped and regtested.
Ok for mainline?
Regards,
Volker
2005-02-19 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/19980
* decl.c (start_preparsed_function): Robustify.
PR c++/19980
* g++.dg/template/redecl3.C: New test.
===================================================================
--- gcc/gcc/cp/decl.c 27 Jan 2005 07:32:20 -0000 1.1355
+++ gcc/gcc/cp/decl.c 15 Feb 2005 19:18:28 -0000
@@ -9917,7 +9917,11 @@ start_preparsed_function (tree decl1, tr
class scope, current_class_type will be NULL_TREE until set above
by push_nested_class.) */
if (processing_template_decl)
- decl1 = push_template_decl (decl1);
+ {
+ tree newdecl1 = push_template_decl (decl1);
+ if (newdecl1 != error_mark_node)
+ decl1 = newdecl1;
+ }
/* We are now in the scope of the function being defined. */
current_function_decl = decl1;
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/redecl3.C 1970-01-01 01:00:00.000000000 +0100
+++ gcc/gcc/testsuite/g++.dg/template/redecl3.C 2005-02-19 18:04:54.000000000 +0100
@@ -0,0 +1,7 @@
+// PR c++/19980
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+
+// { dg-do compile }
+
+int foo; // { dg-error "previous declaration" }
+template<int> void foo() {} // { dg-error "redeclared" }
===================================================================