c++: [[no_unique_address]] in empty base [PR98463]
authorJason Merrill <jason@redhat.com>
Fri, 22 Jan 2021 18:17:10 +0000 (13:17 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 25 Jan 2021 15:36:27 +0000 (10:36 -0500)
commit94ff4c9dd98f39280fba22d1ad0958fb25a5363b
treeab662beb03a2eb1997cef9866d0c14c4d3f5f3b4
parent10c83fb7131779ee27fbaa9091065ca6cfedc0c5
c++: [[no_unique_address]] in empty base [PR98463]

In this testcase, cxx_eval_store_expression got confused trying to build up
CONSTRUCTORs for initializing a subobject because the subobject is a member
of an empty base.  In C++14 mode and below we don't build FIELD_DECLs for
empty bases, so the CONSTRUCTOR skipped the empty base, and treated the
member as a member of the derived class, which breaks.

Fixed by recognizing this situation and giving up on trying to build a
CONSTRUCTOR for the inner target at that point; since it doesn't have any
data, we don't need to actually store anything.

gcc/cp/ChangeLog:

PR c++/98463
* constexpr.c (get_or_insert_ctor_field): Add check.
(cxx_eval_store_expression): Handle discontinuity of refs.

gcc/testsuite/ChangeLog:

PR c++/98463
* g++.dg/cpp2a/no_unique_address8.C: New test.
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp2a/no_unique_address8.C [new file with mode: 0644]