c++: EH and partially constructed aggr temp [PR66139]
authorJason Merrill <jason@redhat.com>
Thu, 5 Mar 2020 20:50:45 +0000 (15:50 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 7 Jan 2022 00:23:17 +0000 (19:23 -0500)
commit4f6bc28fc7dd86bd9e7408cbf28de1e973dd1eda
tree0a38c0720e5d43cd717dbef2244dad9d139dd830
parentbeaee0a871b6485d20573fe050b1fd425581e56a
c++: EH and partially constructed aggr temp [PR66139]

Now that PR94041 is fixed, I can return to addressing PR66139, missing
cleanups for partially constructed aggregate temporaries.  My previous
approach of calling split_nonconstant_init in cp_gimplify_init_expr broke
because gimplification is too late to be introducing destructor calls.  So
instead I now call it under cp_fold_function, just before cp_genericize;
doing it from cp_genericize itself ran into trouble with the rewriting of
invisible references.

So now the prediction in cp_gimplify_expr that cp_gimplify_init_expr
might need to replace references to TARGET_EXPR_SLOT within
TARGET_EXPR_INITIAL has come to pass.  constexpr.c already had the simple
search-and-replace tree walk I needed, but it needed to be fixed to actually
replace all occurrences instead of just the first one.

Handling of VEC_INIT_EXPR at gimplify time had similar issues that we worked
around with build_vec_init_elt, so I'm moving that to cp_fold_function as
well.  But it seems that build_vec_init_elt is still useful for setting the
VEC_INIT_EXPR_IS_CONSTEXPR flag, so I'm leaving it alone.

This also fixes 52320, because build_aggr_init of each X from build_vec_init
builds an INIT_EXPR rather than call split_nonconstant_init at that point,
and now that INIT_EXPR gets split later.

PR c++/66139
PR c++/52320

gcc/cp/ChangeLog:

* constexpr.c (replace_decl): Rename from replace_result_decl.
* cp-tree.h (replace_decl): Declare it.
* cp-gimplify.c (cp_gimplify_init_expr): Call it.
(cp_gimplify_expr): Don't handle VEC_INIT_EXPR.
(cp_genericize_init, cp_genericize_init_expr)
(cp_genericize_target_expr): New.
(cp_fold_r): Call them.
* tree.c (build_array_copy): Add a TARGET_EXPR.
* typeck2.c (digest_init_r): Look through a TARGET_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist116.C: New test.
* g++.dg/cpp0x/initlist117.C: New test.
* g++.dg/cpp0x/lambda/lambda-eh.C: New test.
* g++.dg/eh/aggregate1.C: New test.
gcc/cp/constexpr.c
gcc/cp/cp-gimplify.c
gcc/cp/cp-tree.h
gcc/cp/tree.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp0x/initlist116.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/initlist117.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh.C [new file with mode: 0644]
gcc/testsuite/g++.dg/eh/aggregate1.C [new file with mode: 0644]