When we're building up the constructor for the anonymous union type, build_anon_member_initialization was getting confused, assuming that anything it found with anonymous union type would be a COMPONENT_REF. But within the constructor, *this also has anonymous union type.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit c961c6b0c58e0790cac83e6e071b742a53373cfa
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Jan 28 13:42:45 2014 -0500

    	PR c++/58701
    	* semantics.c (build_anon_member_initialization): Stop walking
    	when we run out of COMPONENT_REFs.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 3a8daca..fd6466d 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7515,7 +7515,8 @@ build_anon_member_initialization (tree member, tree init,
       fields.safe_push (TREE_OPERAND (member, 1));
       member = TREE_OPERAND (member, 0);
     }
-  while (ANON_AGGR_TYPE_P (TREE_TYPE (member)));
+  while (ANON_AGGR_TYPE_P (TREE_TYPE (member))
+	 && TREE_CODE (member) == COMPONENT_REF);
 
   /* VEC has the constructor elements vector for the context of FIELD.
      If FIELD is an anonymous aggregate, we will push inside it.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-union5.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-union5.C
new file mode 100644
index 0000000..57dfd59
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-union5.C
@@ -0,0 +1,11 @@
+// PR c++/58701
+// { dg-require-effective-target c++11 }
+// { dg-final { scan-assembler "7" } }
+
+static union
+{
+  union
+  {
+    int i = 7;
+  };
+};

Reply via email to