This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] P0329R4: Designated Initialization
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Nathan Sidwell <nathan at acm dot org>, gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 30 Mar 2018 16:08:06 -0400
- Subject: Re: [C++ PATCH] P0329R4: Designated Initialization
- References: <20171113225305.GD14653@tucnak>
On Mon, Nov 13, 2017 at 5:53 PM, Jakub Jelinek <jakub@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 <jason@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,
+};