diff options
author | Jason Merrill <jason@redhat.com> | 2021-02-08 15:56:11 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-02-08 20:51:24 -0500 |
commit | a8dd2b3e96590ceccead63d28fc91c956a5f1a73 (patch) | |
tree | 5801eaf989c4d925bf56699f2b665979cba8c835 /gcc | |
parent | 2da7ce23cfd81b67f77dc102d6f97dd19363b5f4 (diff) | |
download | gcc-a8dd2b3e96590ceccead63d28fc91c956a5f1a73.zip gcc-a8dd2b3e96590ceccead63d28fc91c956a5f1a73.tar.gz gcc-a8dd2b3e96590ceccead63d28fc91c956a5f1a73.tar.bz2 |
c++: constexpr, union, and no_unique_address [PR98994]
My second patch for 97566 omits nested CONSTRUCTORs for empty fields, but we
do want them for empty union members.
gcc/cp/ChangeLog:
PR c++/98994
PR c++/97566
* constexpr.c (cxx_eval_store_expression): Only skip empty fields in
RECORD_TYPE.
gcc/testsuite/ChangeLog:
PR c++/98994
* g++.dg/cpp2a/no_unique_address12.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/constexpr.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/no_unique_address12.C | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 1dbc2db..53567ad 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -5292,7 +5292,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, type = refs->pop(); tree index = refs->pop(); - if (is_empty_field (index)) + if (code == RECORD_TYPE && is_empty_field (index)) /* Don't build a sub-CONSTRUCTOR for an empty base or field, as they have no data and might have an offset lower than previously declared fields, which confuses the middle-end. The code below will notice diff --git a/gcc/testsuite/g++.dg/cpp2a/no_unique_address12.C b/gcc/testsuite/g++.dg/cpp2a/no_unique_address12.C new file mode 100644 index 0000000..761d208 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/no_unique_address12.C @@ -0,0 +1,12 @@ +// PR c++/98994 +// { dg-do compile { target c++20 } } + +struct empty {}; + +union U { + constexpr U(): a() { } + + [[no_unique_address]] empty a; +}; + +constexpr U u; |