From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 7706F3858D39; Thu, 21 Oct 2021 00:23:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7706F3858D39 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 r12-4586] libstdc++: Remove constraints from std::optional monadic ops [PR102863] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 674dda6be01990c2def9bd7a41d53ec996e8b0ed X-Git-Newrev: 0fac85a24f40ef6098b756e8e8655205f4bfbf3e Message-Id: <20211021002329.7706F3858D39@sourceware.org> Date: Thu, 21 Oct 2021 00:23:29 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Oct 2021 00:23:29 -0000 https://gcc.gnu.org/g:0fac85a24f40ef6098b756e8e8655205f4bfbf3e commit r12-4586-g0fac85a24f40ef6098b756e8e8655205f4bfbf3e Author: Jonathan Wakely Date: Thu Oct 21 01:19:45 2021 +0100 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: --- libstdc++-v3/include/std/optional | 16 ++++++++-------- .../testsuite/20_util/optional/monadic/and_then.cc | 12 ++++++++++++ .../testsuite/20_util/optional/monadic/transform.cc | 12 ++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) 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 requires invocable<_Fn, _Tp&> + template constexpr auto and_then(_Fn&& __f) & { @@ -1060,7 +1060,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Up(); } - template requires invocable<_Fn, const _Tp&> + template constexpr auto and_then(_Fn&& __f) const & { @@ -1072,7 +1072,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Up(); } - template requires invocable<_Fn, _Tp> + template constexpr auto and_then(_Fn&& __f) && { @@ -1084,7 +1084,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Up(); } - template requires invocable<_Fn, const _Tp> + template constexpr auto and_then(_Fn&& __f) const && { @@ -1096,7 +1096,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Up(); } - template requires invocable<_Fn, _Tp&> + template constexpr auto transform(_Fn&& __f) & { @@ -1107,7 +1107,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return optional<_Up>(); } - template requires invocable<_Fn, const _Tp&> + template constexpr auto transform(_Fn&& __f) const & { @@ -1118,7 +1118,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return optional<_Up>(); } - template requires invocable<_Fn, _Tp> + template constexpr auto transform(_Fn&& __f) && { @@ -1129,7 +1129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return optional<_Up>(); } - template requires invocable<_Fn, const _Tp> + template 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 x; + auto answer = x.and_then([](auto& y) { f(y); return std::optional{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 x; + auto answer = x.transform([](auto& y) { f(y); return 42; }); + VERIFY( !answer ); +} + int main() { test_transform(); test_forwarding(); test_copy_elision(); + test_unconstrained(); }