c++: Don't require accessible dtors for some forms of new [PR59238]
authorJason Merrill <jason@redhat.com>
Wed, 9 Dec 2020 03:05:45 +0000 (22:05 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 9 Dec 2020 05:36:07 +0000 (00:36 -0500)
commit4eb28483004f8291c1f17df3b242716a5151c180
tree5c7a70117b394a18685e1d30946071f2b0f7e69e
parentf6e8e2797ebae21e483373e303ec1c7596309625
c++: Don't require accessible dtors for some forms of new [PR59238]

Jakub noticed that in build_new_1 we needed to add tf_no_cleanup to avoid
building a cleanup for a TARGET_EXPR that we already know is going to be
used to initialize something, so the cleanup will never be run.  The best
place to add it is close to where we build the INIT_EXPR; in
cp_build_modify_expr fixes the single-object new, in expand_default_init
fixes array new.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
gcc/cp/ChangeLog:

PR c++/59238
* init.c (expand_default_init): Pass tf_no_cleanup when building
a TARGET_EXPR to go on the RHS of an INIT_EXPR.
* typeck.c (cp_build_modify_expr): Likewise.

gcc/testsuite/ChangeLog:

PR c++/59238
* g++.dg/cpp0x/new4.C: New test.
gcc/cp/init.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/cpp0x/new4.C [new file with mode: 0644]