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 r12-10110] c++: throwing dtor and empty try [PR113088]
Date: Wed, 24 Jan 2024 19:40:45 +0000 (GMT)	[thread overview]
Message-ID: <20240124194045.5A4D8385DC35@sourceware.org> (raw)

https://gcc.gnu.org/g:b0605cd4a12e9162cc56abc69ca1048947c72689

commit r12-10110-gb0605cd4a12e9162cc56abc69ca1048947c72689
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 20 11:06:27 2023 -0500

    c++: throwing dtor and empty try [PR113088]
    
    maybe_splice_retval_cleanup assumed that the function body can't be empty if
    there's a throwing cleanup, but when I added cleanups to try blocks in
    r12-6333-gb10e031458d541 I didn't adjust that assumption.
    
            PR c++/113088
            PR c++/33799
    
    gcc/cp/ChangeLog:
    
            * except.cc (maybe_splice_retval_cleanup): Handle an empty block.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/eh/return2.C: New test.
    
    (cherry picked from commit 02c0b49798228d777610f898cd9d63ebec43656d)

Diff:
---
 gcc/cp/except.cc                  |  8 ++++++--
 gcc/testsuite/g++.dg/eh/return2.C | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc
index b9f49d1bfc6..96e19b18a71 100644
--- a/gcc/cp/except.cc
+++ b/gcc/cp/except.cc
@@ -1345,9 +1345,13 @@ maybe_splice_retval_cleanup (tree compound_stmt, bool is_try)
 	}
 
       /* Skip past other decls, they can't contain a return.  */
-      while (TREE_CODE (tsi_stmt (iter)) == DECL_EXPR)
+      while (!tsi_end_p (iter)
+	     && TREE_CODE (tsi_stmt (iter)) == DECL_EXPR)
 	tsi_next (&iter);
-      gcc_assert (!tsi_end_p (iter));
+
+      if (tsi_end_p (iter))
+	/* Nothing to wrap.  */
+	return;
 
       /* Wrap the rest of the STATEMENT_LIST in a CLEANUP_STMT.  */
       tree stmts = NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/eh/return2.C b/gcc/testsuite/g++.dg/eh/return2.C
new file mode 100644
index 00000000000..b467d7494af
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/return2.C
@@ -0,0 +1,26 @@
+// PR c++/113088
+
+#if __cplusplus >= 201103L
+#define THROWS noexcept(false)
+#else
+#define THROWS
+#endif
+
+struct X {
+  ~X() {}
+};
+
+struct Y {
+  ~Y() THROWS {}
+};
+
+X foo() {
+  try {
+    return X();
+  } catch (...) {
+    Y();
+    return X();
+  }
+
+  try { } catch (...) { }
+}

                 reply	other threads:[~2024-01-24 19:40 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=20240124194045.5A4D8385DC35@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: link
Be 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).