[patch] Fix PR c++/27951: ICE with invalid anonymous union

Volker Reichelt reichelt@igpm.rwth-aachen.de
Thu Jun 8 10:18:00 GMT 2006


The following invalid code snippet triggers an ICE in the C++ frontend:

  void foo()
  {
      int i;
      union { int i; };
  }

bug.cc: In function 'void foo()':
bug.cc:4: error: redeclaration of 'int i'
bug.cc:3: error: 'int i' previously declared here
bug.cc:4: internal compiler error: tree check: expected tree that contains 'decl minimal' structure, have 'error_mark'  in finish_anon_union, at cp/decl2.c:1121
Please submit a full bug report, [etc.]

The ICE happens because build_anon_union_vars which is called from
finish_anon_union returns an error_mark_node in the case above.
However, there's no check for this error condition and the ICE happens
when DECL_NAME is applied to this result.

The patch below fixes the ICE by returning early when an error_mark_node
is encountered.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?

Regards,
Volker

:ADDPATCH C++:


2006-06-08  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27951
	* decl2.c (finish_anon_union): Return early if build_anon_union_vars
	fails.

===================================================================
--- gcc/gcc/cp/decl2.c	2006-06-08 01:38:42 +0200
+++ gcc/gcc/cp/decl2.c	2006-06-08 01:34:53 +0200
@@ -1109,6 +1109,8 @@ finish_anon_union (tree anon_union_decl)
     }
 
   main_decl = build_anon_union_vars (type, anon_union_decl);
+  if (main_decl == error_mark_node)
+    return;
   if (main_decl == NULL_TREE)
     {
       warning (0, "anonymous union with no members");
===================================================================

2006-06-08  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27951
	* g++.dg/other/anon4.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/other/anon4.C	2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/other/anon4.C	2006-06-08 01:42:54 +0200
@@ -0,0 +1,8 @@
+// PR c++/27951
+// { dg-do compile }
+
+void foo()
+{
+    int i;             // { dg-error "previously" }
+    union { int i; };  // { dg-error "redeclaration" }
+}
===================================================================




More information about the Gcc-patches mailing list