Bug 19980 - [4.0/4.1 regression] ICE on invalid template declaration
Summary: [4.0/4.1 regression] ICE on invalid template declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Volker Reichelt
URL:
Keywords: error-recovery, ice-on-invalid-code, monitored, patch
: 20443 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-02-15 19:30 UTC by Volker Reichelt
Modified: 2005-03-22 15:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-26 18:42:23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2005-02-15 19:30:00 UTC
The following invalid code snippet causes an ICE on mainline:

============================
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.]


The following patch fixes the problem for me.
I haven't done any regtesting, though.

===================================================================
--- 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;
===================================================================
Comment 1 Andrew Pinski 2005-02-15 19:50:26 UTC
Confirmed:
: Search converges between 2004-02-01-trunk (#445) and 2004-03-01-trunk (#446).
Comment 2 Volker Reichelt 2005-02-19 21:04:29 UTC
Patch here:
http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01132.html
Comment 3 Andrew Pinski 2005-03-20 17:01:55 UTC
"But, that's too complicated for Stage 3. Your patch is OK."

Comment 4 CVS Commits 2005-03-22 15:07:18 UTC
Subject: Bug 19980

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	reichelt@gcc.gnu.org	2005-03-22 15:07:04

Modified files:
	gcc/cp         : ChangeLog decl.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: redecl3.C 

Log message:
	PR c++/19980
	* decl.c (start_preparsed_function): Robustify.
	
	* g++.dg/template/redecl3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4672&r2=1.4673
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1380&r2=1.1381
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5195&r2=1.5196
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/redecl3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Volker Reichelt 2005-03-22 15:15:00 UTC
Fixed.
Comment 7 Paolo Carlini 2005-03-22 15:36:55 UTC
Hi Volker: probably your patch fixes c++/20443 too! Can you check?
Comment 8 Volker Reichelt 2005-03-22 15:54:31 UTC
*** Bug 20443 has been marked as a duplicate of this bug. ***