public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8249] c++: throwing cleanup after return [PR113347] Date: Wed, 24 Jan 2024 19:39:11 +0000 (GMT) [thread overview] Message-ID: <20240124193911.B7CBB385E000@sourceware.org> (raw) https://gcc.gnu.org/g:713fbaff8b17a01d3b72110f89112851ed43a90a commit r13-8249-g713fbaff8b17a01d3b72110f89112851ed43a90a Author: Jason Merrill <jason@redhat.com> Date: Tue Jan 23 15:41:09 2024 -0500 c++: throwing cleanup after return [PR113347] Here we were assuming that current_retval_sentinel would be set if we have seen a throwing cleanup, but that's not the case if the cleanup is after all returns. This change isn't needed on trunk, where current_retval_sentinel is set for all NRV functions. PR c++/113347 gcc/cp/ChangeLog: * semantics.cc (finalize_nrv_r): Handle null current_retval_sentinel. gcc/testsuite/ChangeLog: * g++.dg/eh/return3.C: New test. Diff: --- gcc/cp/semantics.cc | 3 ++- gcc/testsuite/g++.dg/eh/return3.C | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 02838775003..ff5252905fe 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -4953,7 +4953,8 @@ finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) /* If a cleanup might throw, we need to clear current_retval_sentinel on the exception path so an outer cleanup added by maybe_splice_retval_cleanup doesn't run. */ - if (cp_function_chain->throwing_cleanup) + if (current_retval_sentinel + && cp_function_chain->throwing_cleanup) { tree clear = build2 (MODIFY_EXPR, boolean_type_node, current_retval_sentinel, diff --git a/gcc/testsuite/g++.dg/eh/return3.C b/gcc/testsuite/g++.dg/eh/return3.C new file mode 100644 index 00000000000..76aa50d523d --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/return3.C @@ -0,0 +1,17 @@ +// PR c++/113347 + +#if __cplusplus < 201103L +#define THROWS +#else +#define THROWS noexcept(false) +#endif + +struct A { ~A(); }; +struct B { ~B() THROWS; }; + +A f() +{ + A a; + return a; + B(); +}
reply other threads:[~2024-01-24 19:39 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240124193911.B7CBB385E000@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).