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.
(cherry picked from commit
e47df5eb56c4e7aca0d3e50826e5aaa1887fa446)
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>)
--- /dev/null
+// { 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)()) );