public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10718] c++: designator and anon struct [PR101767]
@ 2022-05-12 21:14 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-05-12 21:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:846bff4d4659d9b2026da574194599f38a00cc79

commit r10-10718-g846bff4d4659d9b2026da574194599f38a00cc79
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 18 14:36:19 2022 -0400

    c++: designator and anon struct [PR101767]
    
    We found .x in the anonymous struct, but then didn't find .y there; we
    should decide that means we're done with the struct rather than that the
    code is wrong.
    
            PR c++/101767
    
    gcc/cp/ChangeLog:
    
            * decl.c (reshape_init_class): Back out of anon struct
            if a designator doesn't match.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/ext/anon-struct10.C: New test.

Diff:
---
 gcc/cp/decl.c                            |  5 +++++
 gcc/testsuite/g++.dg/ext/anon-struct10.C | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index e923fb0fe13..5bd6c964a3a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6251,6 +6251,11 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
 	      return error_mark_node;
 	    }
 
+	  if (!field && ANON_AGGR_TYPE_P (type))
+	    /* Apparently the designator isn't for a member of this anonymous
+	       struct, so head back to the enclosing class.  */
+	    break;
+
 	  if (!field || TREE_CODE (field) != FIELD_DECL)
 	    {
 	      if (complain & tf_error)
diff --git a/gcc/testsuite/g++.dg/ext/anon-struct10.C b/gcc/testsuite/g++.dg/ext/anon-struct10.C
new file mode 100644
index 00000000000..9b01bf3fada
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/anon-struct10.C
@@ -0,0 +1,21 @@
+// PR c++/101767
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wno-pedantic" }
+
+typedef struct {
+  struct {
+    int x;
+  };
+  union {
+    int y;
+    float z;
+  };
+} S;
+
+void foo(void)
+{
+  [[maybe_unused]] S a = {
+    .x = 1,
+    .y = 0
+  };
+}


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

only message in thread, other threads:[~2022-05-12 21:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 21:14 [gcc r10-10718] c++: designator and anon struct [PR101767] 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).