public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add noexcept-specifier to std::reference_wrapper::operator()
Date: Wed, 31 Aug 2022 14:39:01 +0100	[thread overview]
Message-ID: <20220831133901.63261-1-jwakely@redhat.com> (raw)

Tested x86_64-linux, pushed to trunk.

-- >8 --

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.
---
 libstdc++-v3/include/bits/refwrap.h               |  3 ++-
 .../20_util/reference_wrapper/invoke-noexcept.cc  | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc

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<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 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 <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)()) );
-- 
2.37.2


                 reply	other threads:[~2022-08-31 13:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220831133901.63261-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).