]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Copy elision and [[no_unique_address]]. [PR93711]
authorJason Merrill <jason@redhat.com>
Wed, 12 Aug 2020 09:45:02 +0000 (05:45 -0400)
committerGiuliano Belinassi <giuliano.belinassi@usp.br>
Mon, 17 Aug 2020 18:08:13 +0000 (15:08 -0300)
commit8d249461feb6cd707b1fcb1a936baeaeee0633de
treeb256473af8402f74e819e0456c2d611625e2551c
parent487952eb6244fbd5ba720313a8d39e5732282215
c++: Copy elision and [[no_unique_address]]. [PR93711]

We don't elide a copy from a function returning a class by value into a base
because that can overwrite data laid out in the tail padding of the base
class; we need to handle [[no_unique_address]] fields the same way, or we
ICE when the middle-end wants to create a temporary object of a
TYPE_NEEDS_CONSTRUCTING type.

This means that we can't always express initialization of a field with
INIT_EXPR from a TARGET_EXPR the way we usually do, so I needed
to change several places that were assuming that was sufficient.

This also fixes 90254, the same problem with C++17 aggregate initialization
of a base.

gcc/cp/ChangeLog:

PR c++/90254
PR c++/93711
* cp-tree.h (unsafe_return_slot_p): Declare.
* call.c (is_base_field_ref): Rename to unsafe_return_slot_p.
(build_over_call): Check unsafe_return_slot_p.
(build_special_member_call): Likewise.
* init.c (expand_default_init): Likewise.
* typeck2.c (split_nonconstant_init_1): Likewise.

gcc/testsuite/ChangeLog:

PR c++/90254
PR c++/93711
* g++.dg/cpp1z/aggr-base10.C: New test.
* g++.dg/cpp2a/no_unique_address7.C: New test.
* g++.dg/cpp2a/no_unique_address7a.C: New test.
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/init.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp1z/aggr-base10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/no_unique_address7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/no_unique_address7a.C [new file with mode: 0644]