public inbox for gcc-patches@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++: Remove constraints from std::optional monadic ops [PR102863]
Date: Thu, 21 Oct 2021 01:23:46 +0100	[thread overview]
Message-ID: <YXCzEkqqDm2TEQcS@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 577 bytes --]

The constraints on transform and and_then can cause errors when checking
satisfaction. The constraints that were present in R6 of the paper were
moved for he final F8 revision, and so should have been included in the
implementation.

libstdc++-v3/ChangeLog:

	PR libstdc++/102863
	* include/std/optional (optional::and_then, optional::transform):
	Remove requires-clause.
	* testsuite/20_util/optional/monadic/and_then.cc: Check
	overload resolution doesn't cause errors.
	* testsuite/20_util/optional/monadic/transform.cc: Likewise.

Tested x86_64-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 4329 bytes --]

commit 0fac85a24f40ef6098b756e8e8655205f4bfbf3e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Oct 21 01:19:45 2021

    libstdc++: Remove constraints from std::optional monadic ops [PR102863]
    
    The constraints on transform and and_then can cause errors when checking
    satisfaction. The constraints that were present in R6 of the paper were
    moved for he final F8 revision, and so should have been included in the
    implementation.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/102863
            * include/std/optional (optional::and_then, optional::transform):
            Remove requires-clause.
            * testsuite/20_util/optional/monadic/and_then.cc: Check
            overload resolution doesn't cause errors.
            * testsuite/20_util/optional/monadic/transform.cc: Likewise.

diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index eac91d3c160..783d7ca1b64 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -1048,7 +1048,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       // [optional.monadic]
 
-      template<typename _Fn> requires invocable<_Fn, _Tp&>
+      template<typename _Fn>
 	constexpr auto
 	and_then(_Fn&& __f) &
 	{
@@ -1060,7 +1060,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return _Up();
 	}
 
-      template<typename _Fn> requires invocable<_Fn, const _Tp&>
+      template<typename _Fn>
 	constexpr auto
 	and_then(_Fn&& __f) const &
 	{
@@ -1072,7 +1072,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return _Up();
 	}
 
-      template<typename _Fn> requires invocable<_Fn, _Tp>
+      template<typename _Fn>
 	constexpr auto
 	and_then(_Fn&& __f) &&
 	{
@@ -1084,7 +1084,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return _Up();
 	}
 
-      template<typename _Fn> requires invocable<_Fn, const _Tp>
+      template<typename _Fn>
 	constexpr auto
 	and_then(_Fn&& __f) const &&
 	{
@@ -1096,7 +1096,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return _Up();
 	}
 
-      template<typename _Fn> requires invocable<_Fn, _Tp&>
+      template<typename _Fn>
 	constexpr auto
 	transform(_Fn&& __f) &
 	{
@@ -1107,7 +1107,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return optional<_Up>();
 	}
 
-      template<typename _Fn> requires invocable<_Fn, const _Tp&>
+      template<typename _Fn>
 	constexpr auto
 	transform(_Fn&& __f) const &
 	{
@@ -1118,7 +1118,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return optional<_Up>();
 	}
 
-      template<typename _Fn> requires invocable<_Fn, _Tp>
+      template<typename _Fn>
 	constexpr auto
 	transform(_Fn&& __f) &&
 	{
@@ -1129,7 +1129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return optional<_Up>();
 	}
 
-      template<typename _Fn> requires invocable<_Fn, const _Tp>
+      template<typename _Fn>
 	constexpr auto
 	transform(_Fn&& __f) const &&
 	{
diff --git a/libstdc++-v3/testsuite/20_util/optional/monadic/and_then.cc b/libstdc++-v3/testsuite/20_util/optional/monadic/and_then.cc
index 02dcafe6c58..f69ab952643 100644
--- a/libstdc++-v3/testsuite/20_util/optional/monadic/and_then.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/monadic/and_then.cc
@@ -113,8 +113,20 @@ test_forwarding()
 
 static_assert( test_forwarding() );
 
+void f(int&) { }
+
+void
+test_unconstrained()
+{
+  // PR libstc++/102863 - Optional monadic ops should not be constrained
+  std::optional<int> x;
+  auto answer = x.and_then([](auto& y) { f(y); return std::optional<int>{42}; });
+  VERIFY( !answer );
+}
+
 int main()
 {
   test_and_then();
   test_forwarding();
+  test_unconstrained();
 }
diff --git a/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc b/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc
index 13977b8ba8d..356c94de6d0 100644
--- a/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc
@@ -132,9 +132,21 @@ test_copy_elision()
 
 static_assert( test_copy_elision() );
 
+void f(int&) { }
+
+void
+test_unconstrained()
+{
+  // PR libstc++/102863 - Optional monadic ops should not be constrained
+  std::optional<int> x;
+  auto answer = x.transform([](auto& y) { f(y); return 42; });
+  VERIFY( !answer );
+}
+
 int main()
 {
   test_transform();
   test_forwarding();
   test_copy_elision();
+  test_unconstrained();
 }

             reply	other threads:[~2021-10-21  0:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21  0:23 Jonathan Wakely [this message]
2021-10-21  0:25 ` Jonathan Wakely

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=YXCzEkqqDm2TEQcS@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).