[patch] Fix PR c++/19980: ICE on invalid template declaration

Volker Reichelt reichelt@igpm.rwth-aachen.de
Tue Feb 22 15:38:00 GMT 2005


On 20 Feb, Mark Mitchell wrote:
> Volker Reichelt wrote:

>> 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.
> 
> Ugh.
> 
> The right fix for this might really be to have start_preparsed function 
> return false in this case (it presently does not have a return value), 
> after popping any pushed context, and then have callers skip the body of 
> the function.  Trying to actually do anything in the body of such a 
> function is risky.
> 
> But, that's too complicated for Stage 3.  Your patch is OK.

How about adding a comment to the patch?

===================================================================
--- 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,12 @@ 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);
+    {
+      /* FIXME: Handle error_mark_node more gracefully.  */
+      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;
===================================================================

Regards,
Volker




More information about the Gcc-patches mailing list