From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id D81B9383E059; Wed, 31 Aug 2022 13:38:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D81B9383E059 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661953126; bh=hRSvqDfGX1kDU25qP8b7flj2/E5gqj4LZVZvXQ+5y0U=; h=From:To:Subject:Date:From; b=psXeRvS/XTEtdXxJhHV6k/zrVbAxOIT8Hd56YEA/YoulKiYJXE4Q9veeuUU3EyR+I riSbelllrl0Fw2IusCInVS9L9i5C1HD1SnTg16tu6RPo9HDuxa5GD1zUtiT+c/CEu1 DOqugaUq6mwjqhmcs0ePwLosbwoJ+4Rw11To5rBo= 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-2312] libstdc++: Add noexcept-specifier to std::reference_wrapper::operator() X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 5d27fcd993e4519fc05224f48bd2492b6cf52be1 X-Git-Newrev: e47df5eb56c4e7aca0d3e50826e5aaa1887fa446 Message-Id: <20220831133846.D81B9383E059@sourceware.org> Date: Wed, 31 Aug 2022 13:38:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e47df5eb56c4e7aca0d3e50826e5aaa1887fa446 commit r13-2312-ge47df5eb56c4e7aca0d3e50826e5aaa1887fa446 Author: Jonathan Wakely Date: Wed Aug 31 13:57:34 2022 +0100 libstdc++: Add noexcept-specifier to std::reference_wrapper::operator() This isn't required by the standard, but there's an LWG issue suggesting to add it. Also use __invoke_result instead of result_of, to match the spec in recent standards. libstdc++-v3/ChangeLog: * include/bits/refwrap.h (reference_wrapper::operator()): Add noexcept-specifier and use __invoke_result instead of result_of. * testsuite/20_util/reference_wrapper/invoke-noexcept.cc: New test. Diff: --- libstdc++-v3/include/bits/refwrap.h | 3 ++- .../20_util/reference_wrapper/invoke-noexcept.cc | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/refwrap.h b/libstdc++-v3/include/bits/refwrap.h index 8016f87478e..976902bc7bc 100644 --- a/libstdc++-v3/include/bits/refwrap.h +++ b/libstdc++-v3/include/bits/refwrap.h @@ -348,8 +348,9 @@ _GLIBCXX_MEM_FN_TRAITS(&& noexcept, false_type, true_type) template _GLIBCXX20_CONSTEXPR - typename result_of<_Tp&(_Args&&...)>::type + typename __invoke_result<_Tp&, _Args...>::type operator()(_Args&&... __args) const + noexcept(__is_nothrow_invocable<_Tp&, _Args...>::value) { #if __cplusplus > 201703L if constexpr (is_object_v) diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc new file mode 100644 index 00000000000..91b5d097f08 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc @@ -0,0 +1,15 @@ +// { dg-do compile { target c++11 } } + +// C++11 20.8.3.4 reference_wrapper invocation [refwrap.invoke] + +#include + +struct F +{ + int operator()() noexcept(true) { return 1; } + int operator()() const noexcept(false) { return 2; } +}; + +F f; +static_assert( noexcept(std::ref(f)()) ); +static_assert( ! noexcept(std::cref(f)()) );