Fix designated initializer for anonymous union.
authorJason Merrill <jason@redhat.com>
Fri, 30 Mar 2018 20:08:51 +0000 (16:08 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 30 Mar 2018 20:08:51 +0000 (16:08 -0400)
* typeck2.c (process_init_constructor_record): Use
init_list_type_node for the CONSTRUCTOR around an anonymous union
designated initializer.

From-SVN: r258982

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp2a/desig9.C [new file with mode: 0644]

index 13b2435..3ea9faa 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-30  Jason Merrill  <jason@redhat.com>
+
+       * typeck2.c (process_init_constructor_record): Use
+       init_list_type_node for the CONSTRUCTOR around an anonymous union
+       designated initializer.
+
 2018-03-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/84791
index 464e8a7..3aae0a3 100644 (file)
@@ -1435,7 +1435,8 @@ process_init_constructor_record (tree type, tree init, int nested,
                   designated-initializer-list { D }, where D is the
                   designated-initializer-clause naming a member of the
                   anonymous union object.  */
-               next = build_constructor_single (type, ce->index, ce->value);
+               next = build_constructor_single (init_list_type_node,
+                                                ce->index, ce->value);
              else
                {
                  ce = NULL;
diff --git a/gcc/testsuite/g++.dg/cpp2a/desig9.C b/gcc/testsuite/g++.dg/cpp2a/desig9.C
new file mode 100644 (file)
index 0000000..990a2aa
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "" }
+
+struct A {
+  union {
+    int a;
+    char b;
+  };
+};
+
+struct A x = {
+  .a = 5,
+};