On Mon, Nov 13, 2017 at 5:53 PM, Jakub Jelinek <ja...@redhat.com> wrote: > + /* If the element is an anonymous union object and the > + initializer list is a designated-initializer-list, the > + anonymous union object is initialized by the > + 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);
We need to use init_list_type_node for the CONSTRUCTOR so that digest_init works properly. Applying to trunk.
commit 9c34bc519821ca90cb37dce05744f404bb3a9991 Author: Jason Merrill <ja...@redhat.com> Date: Fri Mar 30 15:30:45 2018 -0400 Fix designated initializer for anonymous union. * typeck2.c (process_init_constructor_record): Use init_list_type_node for the CONSTRUCTOR around an anonymous union designated initializer. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 464e8a7c3b1..3aae0a362d5 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -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 index 00000000000..990a2aa20a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/desig9.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "" } + +struct A { + union { + int a; + char b; + }; +}; + +struct A x = { + .a = 5, +};