Message ID | 20240228145234.214146-1-jwakely@redhat.com |
---|---|
State | New |
Headers | show |
Series | [committed] libstdc++: Fix noexcept on dtors in <experimental/scope> [PR114152] | expand |
Oops, sorry, I CC'd the wrong Victor on this patch (you've both reported libstdc++ bugs today and I grabbed the email address from the wrong browser tab). On Wed, 28 Feb 2024 at 14:53, Jonathan Wakely wrote: > > Tested x86_64-linux, pushed to trunk. Backport to gcc-13 to follow. > > -- >8 -- > > 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. > --- > libstdc++-v3/include/experimental/scope | 6 ++--- > .../experimental/scopeguard/114152.cc | 24 +++++++++++++++++++ > 2 files changed, 27 insertions(+), 3 deletions(-) > create mode 100644 libstdc++-v3/testsuite/experimental/scopeguard/114152.cc > > 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()) ); > -- > 2.43.0 >
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()) );