[Bug c++/19980] New: [4.0 regression] ICE on invalid template declaration

reichelt at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Tue Feb 15 23:15:00 GMT 2005


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;
===================================================================

-- 
           Summary: [4.0 regression] ICE on invalid template declaration
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: ice-on-invalid-code, error-recovery, monitored
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19980



More information about the Gcc-bugs mailing list