The compiler was wrongly clearing uses_unions_p when recursing into the
anonymous struct, breaking the union logic.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit e7830050a2bd41b5109b9e09512b0f285c47001c
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue Aug 2 21:08:57 2011 +0000
PR c++/49803
* init.c (sort_mem_initializers): Initialize uses_unions_p here.
(build_field_list): Not here.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177213 138bc75d-0d04-0410-961f-82ee72b054a4
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 52b9484..31171cf 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -655,8 +655,6 @@ build_field_list (tree t, tree list, int *uses_unions_p)
{
tree fields;
- *uses_unions_p = 0;
-
/* Note whether or not T is a union. */
if (TREE_CODE (t) == UNION_TYPE)
*uses_unions_p = 1;
@@ -710,7 +708,7 @@ sort_mem_initializers (tree t, tree mem_inits)
tree next_subobject;
VEC(tree,gc) *vbases;
int i;
- int uses_unions_p;
+ int uses_unions_p = 0;
/* Build up a list of initializations. The TREE_PURPOSE of entry
will be the subobject (a FIELD_DECL or BINFO) to initialize. The
diff --git a/gcc/testsuite/g++.dg/cpp0x/union5.C b/gcc/testsuite/g++.dg/cpp0x/union5.C
new file mode 100644
index 0000000..423b348
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/union5.C
@@ -0,0 +1,23 @@
+// PR c++/49803
+// { dg-options -std=c++0x }
+
+struct X
+{
+ X() = delete;
+};
+
+union Y
+{
+ // N3291=11-0061 12.6.2/8 says no initialization of
+ // of other variant members (i.e. m_x) should
+ // be performed.
+ Y() : m_char1{ }
+ { }
+
+ struct
+ {
+ char m_char1;
+ };
+
+ X m_x;
+};