public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-8371] libstdc++: Fix noexcept on dtors in <experimental/scope> [PR114152]
Date: Fri,  1 Mar 2024 10:52:46 +0000 (GMT)	[thread overview]
Message-ID: <20240301105246.A47E53858D39@sourceware.org> (raw)

https://gcc.gnu.org/g:89e7b77df1aefb01aadfacae83170b24a4c4d274

commit r13-8371-g89e7b77df1aefb01aadfacae83170b24a4c4d274
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Feb 28 14:45:18 2024 +0000

    libstdc++: Fix noexcept on dtors in <experimental/scope> [PR114152]
    
    The PR points out that the destructors all have incorrect
    noexcept-specifiers.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/114152
            * include/experimental/scope (scope_exit scope_fail): Make
            destructor unconditionally noexcept.
            (scope_sucess): Fix noexcept-specifier.
            * testsuite/experimental/scopeguard/114152.cc: New test.
    
    (cherry picked from commit 80c386cb20d38ebc55f30a79418fabfbed904b87)

Diff:
---
 libstdc++-v3/include/experimental/scope            |  6 +++---
 .../testsuite/experimental/scopeguard/114152.cc    | 24 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/experimental/scope b/libstdc++-v3/include/experimental/scope
index 5dbeac14795..ea273e8c095 100644
--- a/libstdc++-v3/include/experimental/scope
+++ b/libstdc++-v3/include/experimental/scope
@@ -97,7 +97,7 @@ namespace experimental::inline fundamentals_v3
       scope_exit& operator=(const scope_exit&) = delete;
       scope_exit& operator=(scope_exit&&) = delete;
 
-      ~scope_exit() noexcept(noexcept(this->_M_exit_function))
+      ~scope_exit() noexcept
       {
 	if (_M_execute_on_destruction)
 	  _M_exit_function();
@@ -157,7 +157,7 @@ namespace experimental::inline fundamentals_v3
       scope_fail& operator=(const scope_fail&) = delete;
       scope_fail& operator=(scope_fail&&) = delete;
 
-      ~scope_fail() noexcept(noexcept(this->_M_exit_function))
+      ~scope_fail() noexcept
       {
 	if (std::uncaught_exceptions() > _M_uncaught_init)
 	  _M_exit_function();
@@ -211,7 +211,7 @@ namespace experimental::inline fundamentals_v3
       scope_success& operator=(const scope_success&) = delete;
       scope_success& operator=(scope_success&&) = delete;
 
-      ~scope_success() noexcept(noexcept(this->_M_exit_function))
+      ~scope_success() noexcept(noexcept(this->_M_exit_function()))
       {
 	if (std::uncaught_exceptions() <= _M_uncaught_init)
 	  _M_exit_function();
diff --git a/libstdc++-v3/testsuite/experimental/scopeguard/114152.cc b/libstdc++-v3/testsuite/experimental/scopeguard/114152.cc
new file mode 100644
index 00000000000..63c1f710e9f
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/scopeguard/114152.cc
@@ -0,0 +1,24 @@
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/114152
+// Wrong exception specifiers for LFTSv3 scope guard destructors
+
+#include <experimental/scope>
+
+using namespace std::experimental;
+
+struct F {
+  void operator()() noexcept(false);
+};
+
+static_assert( noexcept(std::declval<scope_exit<F>&>().~scope_exit()) );
+static_assert( noexcept(std::declval<scope_fail<F>&>().~scope_fail()) );
+static_assert( ! noexcept(std::declval<scope_success<F>&>().~scope_success()) );
+
+struct G {
+  void operator()() noexcept(true);
+};
+
+static_assert( noexcept(std::declval<scope_exit<G>&>().~scope_exit()) );
+static_assert( noexcept(std::declval<scope_fail<G>&>().~scope_fail()) );
+static_assert( noexcept(std::declval<scope_success<G>&>().~scope_success()) );

                 reply	other threads:[~2024-03-01 10:52 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=20240301105246.A47E53858D39@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-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).