c++: clean up ref-extended temp on throwing dtor [PR53868]
authorJason Merrill <jason@redhat.com>
Wed, 5 Jan 2022 16:18:25 +0000 (11:18 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 7 Jan 2022 00:25:42 +0000 (19:25 -0500)
commit4c6afbbd48f0c40ddf949bc403d9bd5f5e14204f
tree68738365efc46a2ecbaf807eeebd45f39e1d9778
parent2fbc45486e13facfeb05bd6ddf70ff9973a30a3c
c++: clean up ref-extended temp on throwing dtor [PR53868]

We have wrap_temporary_cleanups to handle the EH region nesting problems
between cleanups for complete variables and cleanups for temporaries used in
their construction, but we weren't calling it for temporaries extended from
binding to a reference.

We still don't want this for array cleanups (since my PR94041 fix), so I
move that exception from initialize_local_var to wrap_temporary_cleanups.

PR c++/53868

gcc/cp/ChangeLog:

* decl.c (cp_finish_decl): Use wrap_temporary_cleanups for
cleanups from set_up_extended_ref_temp.
(wrap_temporary_cleanups): Ignore array cleanups.
(initialize_local_var): Don't check for array here.
* cp-tree.h (BIND_EXPR_VEC_DTOR): New.
* init.c (build_vec_delete_1): Set it.

gcc/testsuite/ChangeLog:

* g++.dg/eh/ref-temp1.C: New test.
* g++.dg/eh/ref-temp2.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/init.c
gcc/testsuite/g++.dg/eh/ref-temp1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/eh/ref-temp2.C [new file with mode: 0644]