commit:     1b262115460489ec8736bfa5102c62656d580fb5
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Thu May 20 22:12:59 2021 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Thu May 20 22:12:59 2021 +0000
URL:        https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=1b262115

10.3.0: backport PR100489: union constructor fix

Reported-by: Martin Kolleck
Bug: https://bugs.gentoo.org/788829
Bug: https://gcc.gnu.org/PR100489
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 10.3.0/gentoo/33_all_ctor-union-PR100489.patch | 71 ++++++++++++++++++++++++++
 10.3.0/gentoo/README.history                   |  3 ++
 2 files changed, 74 insertions(+)

diff --git a/10.3.0/gentoo/33_all_ctor-union-PR100489.patch 
b/10.3.0/gentoo/33_all_ctor-union-PR100489.patch
new file mode 100644
index 0000000..0e25c3e
--- /dev/null
+++ b/10.3.0/gentoo/33_all_ctor-union-PR100489.patch
@@ -0,0 +1,71 @@
+https://bugs.gentoo.org/788829
+https://gcc.gnu.org/PR100489
+
+From a335afe208cd27cf8ee4cb028fb7769700ab6245 Mon Sep 17 00:00:00 2001
+From: Jason Merrill <[email protected]>
+Date: Wed, 19 May 2021 21:12:45 -0400
+Subject: [PATCH] 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.
+---
+ gcc/cp/constexpr.c                   |  4 +---
+ gcc/testsuite/g++.dg/cpp2a/desig18.C | 17 +++++++++++++++++
+ 2 files changed, 18 insertions(+), 3 deletions(-)
+ create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig18.C
+
+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 };
++}
+-- 
+2.31.1
+

diff --git a/10.3.0/gentoo/README.history b/10.3.0/gentoo/README.history
index 8786b6a..a32dce0 100644
--- a/10.3.0/gentoo/README.history
+++ b/10.3.0/gentoo/README.history
@@ -1,3 +1,6 @@
+2              TODO
+       + 33_all_ctor-union-PR100489.patch
+
 1              08 Apr 2021
        + 01_all_default-fortify-source.patch
        + 02_all_default-warn-format-security.patch

Reply via email to