From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id A47E53858D39; Fri, 1 Mar 2024 10:52:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A47E53858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709290366; bh=PAe8/Fga6Jlvf8veMHKkcQy2db0f4rutwHzMNQUHzVU=; h=From:To:Subject:Date:From; b=d4TdRzJsp1vfvgsDlKtKJAtdNj/gekmO/x0YjUtl9ZYzAIv4LvlJ8WZq0GaxA9xqq 8pz3XtCSnz5gwgKKQ3P1RUNK5E6NGZkwzR5iBlp/1yzsowxVScPJuIN16bFZ7wn65Z FcQEyVhgkERamHxThtJ/o0gPzm5dC8RigJo5+Sm0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-8371] libstdc++: Fix noexcept on dtors in [PR114152] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: ce26b0c7f6f22ea76cba6452f072dd4cb7ff896e X-Git-Newrev: 89e7b77df1aefb01aadfacae83170b24a4c4d274 Message-Id: <20240301105246.A47E53858D39@sourceware.org> Date: Fri, 1 Mar 2024 10:52:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:89e7b77df1aefb01aadfacae83170b24a4c4d274 commit r13-8371-g89e7b77df1aefb01aadfacae83170b24a4c4d274 Author: Jonathan Wakely Date: Wed Feb 28 14:45:18 2024 +0000 libstdc++: Fix noexcept on dtors in [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 + +using namespace std::experimental; + +struct F { + void operator()() noexcept(false); +}; + +static_assert( noexcept(std::declval&>().~scope_exit()) ); +static_assert( noexcept(std::declval&>().~scope_fail()) ); +static_assert( ! noexcept(std::declval&>().~scope_success()) ); + +struct G { + void operator()() noexcept(true); +}; + +static_assert( noexcept(std::declval&>().~scope_exit()) ); +static_assert( noexcept(std::declval&>().~scope_fail()) ); +static_assert( noexcept(std::declval&>().~scope_success()) );