public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10091] c++: anon union designated init [PR105925]
@ 2022-06-24  0:45 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-06-24  0:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:553aecc570ce4ef5c751dc39b83bfbde6380f953

commit r11-10091-g553aecc570ce4ef5c751dc39b83bfbde6380f953
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jun 23 16:04:02 2022 -0400

    c++: anon union designated init [PR105925]
    
    This testcase was failing because CONSTRUCTOR_IS_DESIGNATED_INIT wasn't
    getting set on the introduced CONSTRUCTOR for the anonymous union, and
    build_aggr_conv uses that flag to decide whether to pay attention to the
    indexes of the CONSTRUCTOR.  So set the flag when we see a designator rather
    than relying on copying it from another CONSTRUCTOR.
    
            PR c++/105925
    
    gcc/cp/ChangeLog:
    
            * decl.c (reshape_init_array_1): Set
            CONSTRUCTOR_IS_DESIGNATED_INIT here.
            (reshape_init_class): And here.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/desig26.C: New test.

Diff:
---
 gcc/cp/decl.c                        |  3 +++
 gcc/testsuite/g++.dg/cpp2a/desig26.C | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 679ea9c8be7..052378a2e75 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6295,6 +6295,8 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
       tree elt_init;
       constructor_elt *old_cur = d->cur;
 
+      if (d->cur->index)
+	CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
       check_array_designated_initializer (d->cur, index);
       elt_init = reshape_init_r (elt_type, d,
 				 /*first_initializer_p=*/NULL_TREE,
@@ -6447,6 +6449,7 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
 	    }
 	  else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
 	    {
+	      CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
 	      field = get_class_binding (type, d->cur->index);
 	      direct_desig = true;
 	    }
diff --git a/gcc/testsuite/g++.dg/cpp2a/desig26.C b/gcc/testsuite/g++.dg/cpp2a/desig26.C
new file mode 100644
index 00000000000..443fa3d089d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/desig26.C
@@ -0,0 +1,22 @@
+// PR c++/105925
+// { dg-do compile { target c++20 } }
+
+struct V
+{
+    int i;
+    double d;
+};
+
+struct X
+{
+    union
+    {
+        int x;
+        V y;
+    };
+};
+
+X foo()
+{
+    return {.y = {0, 0.0}};
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-24  0:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24  0:45 [gcc r11-10091] c++: anon union designated init [PR105925] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).