From 6d92f13104acabd09f3a2bc6ad41f75bded22771 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 30 Mar 2018 16:08:51 -0400 Subject: [PATCH] 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. From-SVN: r258982 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck2.c | 3 ++- gcc/testsuite/g++.dg/cpp2a/desig9.C | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 13b2435109a..3ea9faa74fb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-30 Jason Merrill + + * 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 PR c++/84791 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, +}; -- 2.30.2