c++: destroy retval on throwing cleanup in try [PR33799]
authorJason Merrill <jason@redhat.com>
Wed, 5 Jan 2022 22:01:12 +0000 (17:01 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 7 Jan 2022 00:25:43 +0000 (19:25 -0500)
commitb10e031458d541f794dfaa08ba606487603a4bb6
tree84098539237e443920e3c21668370bb63a27c841
parent4c6afbbd48f0c40ddf949bc403d9bd5f5e14204f
c++: destroy retval on throwing cleanup in try [PR33799]

My earlier attempt to fix this bug didn't handle the case where both the
return and the throwing cleanup are within a try-block that catches and
discards the exception.  Fixed by adding the retval cleanup to any
try-blocks as well as the function body.  PR102191 pointed out that we also
weren't handling templates properly, so I moved the call out of the parser.

PR c++/33799
PR c++/102191

gcc/cp/ChangeLog:

* except.c (maybe_splice_retval_cleanup): Check
current_binding_level.
* semantics.c (do_poplevel): Call it here.
* parser.c (cp_parser_compound_statement): Not here.

gcc/testsuite/ChangeLog:

* g++.dg/eh/return1.C: Add temporary in try block case.
* g++.dg/cpp2a/constexpr-dtor11.C: New test.
gcc/cp/except.c
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp2a/constexpr-dtor11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/eh/return1.C