public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9857] c++: designated init with anonymous union [PR100489]
@ 2021-05-20 21:36 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-05-20 21:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a335afe208cd27cf8ee4cb028fb7769700ab6245

commit r10-9857-ga335afe208cd27cf8ee4cb028fb7769700ab6245
Author: Jason Merrill <jason@redhat.com>
Date:   Wed May 19 21:12:45 2021 -0400

    c++: designated init with anonymous union [PR100489]
    
    My patch for PR98463 added an assert that tripped on this testcase, because
    we ended up with a U CONSTRUCTOR with an initializer for a, which is not a
    member of U.  We need to wrap the a initializer in another CONSTRUCTOR for
    the anonymous union.
    
    For the GCC 10 branch, just remove the assert.
    
            PR c++/100489
    
    gcc/cp/ChangeLog:
    
            * constexpr.c (get_or_insert_ctor_field): Remove assert.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/desig18.C: New test.

Diff:
---
 gcc/cp/constexpr.c                   |  4 +---
 gcc/testsuite/g++.dg/cpp2a/desig18.C | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index d6fda8b96ee..566ba5b362a 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3361,9 +3361,7 @@ get_or_insert_ctor_field (tree ctor, tree index, int pos_hint = -1)
     }
   else
     {
-      gcc_assert (TREE_CODE (index) == FIELD_DECL
-		  && (same_type_ignoring_top_level_qualifiers_p
-		      (DECL_CONTEXT (index), TREE_TYPE (ctor))));
+      gcc_assert (TREE_CODE (index) == FIELD_DECL);
 
       /* We must keep the CONSTRUCTOR's ELTS in FIELD order.
 	 Usually we meet initializers in that order, but it is
diff --git a/gcc/testsuite/g++.dg/cpp2a/desig18.C b/gcc/testsuite/g++.dg/cpp2a/desig18.C
new file mode 100644
index 00000000000..4851579b7c7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/desig18.C
@@ -0,0 +1,17 @@
+// PR c++/100489
+// { dg-options "" }
+
+union U
+{
+  union
+  {
+    unsigned char a;
+  };
+
+  unsigned char b[1];
+};
+
+void f(unsigned char a)
+{
+  union U u = { .a = a };
+}


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

only message in thread, other threads:[~2021-05-20 21:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 21:36 [gcc r10-9857] c++: designated init with anonymous union [PR100489] 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).