From patchwork Thu Oct 21 00:23:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1544068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Gxqb7Oyr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HZSsN26Byz9sR4 for ; Thu, 21 Oct 2021 11:24:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4CDA3857C60 for ; Thu, 21 Oct 2021 00:24:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4CDA3857C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634775859; bh=9W+qQ4WuvXqvUBr0OxgATUNyAGjweTay9IvLwC2YBQs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Gxqb7OyrARS64/zpd4bxwrDJ3xxBxA+zPvk2ZWSGHQmrqo3mpwL+6YIFvYqKavvxo AMX8zDjUTiLRApJQhMGcCjw/BhheJ+duzh4A4wy5Kxg1g4dexsjbe81bsKL+Cx8Mt1 Y6iui3OpKNXs8YaUbL6oYYWOZPM2W71ddZu8qH/4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id A3CEC3857C67 for ; Thu, 21 Oct 2021 00:23:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A3CEC3857C67 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-455-MAwlDzcQP1ynojotq4Dh1g-1; Wed, 20 Oct 2021 20:23:48 -0400 X-MC-Unique: MAwlDzcQP1ynojotq4Dh1g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B4EC1006AA5; Thu, 21 Oct 2021 00:23:47 +0000 (UTC) Received: from localhost (unknown [10.33.36.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B04660D30; Thu, 21 Oct 2021 00:23:46 +0000 (UTC) Date: Thu, 21 Oct 2021 01:23:46 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Remove constraints from std::optional monadic ops [PR102863] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. commit 0fac85a24f40ef6098b756e8e8655205f4bfbf3e Author: Jonathan Wakely 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 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(); }