aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-08-31 13:57:34 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-08-31 14:28:03 +0100
commite47df5eb56c4e7aca0d3e50826e5aaa1887fa446 (patch)
tree25b14958fc49244ee2578c1c393b0af81836aeaf /libstdc++-v3
parent5d27fcd993e4519fc05224f48bd2492b6cf52be1 (diff)
downloadgcc-e47df5eb56c4e7aca0d3e50826e5aaa1887fa446.zip
gcc-e47df5eb56c4e7aca0d3e50826e5aaa1887fa446.tar.gz
gcc-e47df5eb56c4e7aca0d3e50826e5aaa1887fa446.tar.bz2
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.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/bits/refwrap.h3
-rw-r--r--libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc15
2 files changed, 17 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/refwrap.h b/libstdc++-v3/include/bits/refwrap.h
index 8016f87..976902b 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<typename... _Args>
_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<type>)
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 0000000..91b5d09
--- /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 <functional>
+
+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)()) );