From b10e031458d541f794dfaa08ba606487603a4bb6 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 5 Jan 2022 17:01:12 -0500 Subject: 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/semantics.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/cp/semantics.c') diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 58f45e9..6456547 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -624,6 +624,8 @@ do_poplevel (tree stmt_list) { tree block = NULL; + maybe_splice_retval_cleanup (stmt_list); + if (stmts_are_full_exprs_p ()) block = poplevel (kept_level_p (), 1, 0); -- cgit v1.1