re PR c++/49803 ([C++0x] erroneous variant-member initialization in a union containin...
authorJason Merrill <jason@redhat.com>
Tue, 2 Aug 2011 21:08:57 +0000 (17:08 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 2 Aug 2011 21:08:57 +0000 (17:08 -0400)
PR c++/49803
* init.c (sort_mem_initializers): Initialize uses_unions_p here.
(build_field_list): Not here.

From-SVN: r177213

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/union5.C [new file with mode: 0644]

index bba80e889184dbf7ddacc09800ab254de322abcc..dc138a187b2a465a445ff26c51e82716bf914c5e 100644 (file)
@@ -1,5 +1,9 @@
 2011-08-02  Jason Merrill  <jason@redhat.com>
 
+       PR c++/49803
+       * init.c (sort_mem_initializers): Initialize uses_unions_p here.
+       (build_field_list): Not here.
+
        PR c++/49834
        * parser.c (build_range_temp): Split out from...
        (cp_convert_range_for): ...here.
index 52b948441f2781fbbb0640e8230ddb8ceb4d95ee..31171cfa68653de8a7b4f0e687470c48688e1a6d 100644 (file)
@@ -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
index 82f2776ba464a681f9ffae2ce87276cc39d0f167..6b471694d3ce82abf3187abb53b00561d4f54700 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-02  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49803
+       * g++.dg/cpp0x/union5.C: New.
+
 2011-08-02  Daniel Kraft  <d@domob.eu>
 
        PR fortran/49885
diff --git a/gcc/testsuite/g++.dg/cpp0x/union5.C b/gcc/testsuite/g++.dg/cpp0x/union5.C
new file mode 100644 (file)
index 0000000..423b348
--- /dev/null
@@ -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;
+};