From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2BE36388C012 for ; Mon, 14 Jun 2021 13:07:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2BE36388C012 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-479-0mlpndF0Odi-BXwadQmqIg-1; Mon, 14 Jun 2021 09:07:12 -0400 X-MC-Unique: 0mlpndF0Odi-BXwadQmqIg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F18E2802690; Mon, 14 Jun 2021 13:07:11 +0000 (UTC) Received: from localhost (unknown [10.33.36.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CEEB5C233; Mon, 14 Jun 2021 13:07:11 +0000 (UTC) Date: Mon, 14 Jun 2021 14:07:10 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed 1/2] libstdc++: Change [cmp.alg] assertions to constraints Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="mnAOKjFTk4f0lNnv" Content-Disposition: inline X-Spam-Status: No, score=-13.9 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jun 2021 13:07:19 -0000 --mnAOKjFTk4f0lNnv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This moves the same_as, decay_t<_Up>> checks from the [cmp.alg] function bodies into their constraints. Also add a test for the compare_xxx_order_fallback algorithms. libstdc++-v3/ChangeLog: * libsupc++/compare (__decayed_same_as): New helper concept. (strong_order, weak_order, partial_order): Constrain with new concept instead of using static_assert. (compare_strong_order_fallback, compare_weak_order_fallback) (compare_partial_order_fallback): Likewise. Do not deduce return types. Remove redundant if-constexpr checks. * testsuite/18_support/comparisons/algorithms/fallback.cc: New test. Tested powerpc64le-linux. Committed to trunk. --mnAOKjFTk4f0lNnv Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit e2c79b968ff95421c31a5a9a1b80b11321fe70d2 Author: Jonathan Wakely Date: Mon Jun 14 12:25:43 2021 libstdc++: Change [cmp.alg] assertions to constraints This moves the same_as, decay_t<_Up>> checks from the [cmp.alg] function bodies into their constraints. Also add a test for the compare_xxx_order_fallback algorithms. libstdc++-v3/ChangeLog: * libsupc++/compare (__decayed_same_as): New helper concept. (strong_order, weak_order, partial_order): Constrain with new concept instead of using static_assert. (compare_strong_order_fallback, compare_weak_order_fallback) (compare_partial_order_fallback): Likewise. Do not deduce return types. Remove redundant if-constexpr checks. * testsuite/18_support/comparisons/algorithms/fallback.cc: New test. diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index 82d00889272..b1f342113f1 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -600,6 +600,9 @@ namespace std // FIXME: || floating_point> || __cmp3way; + template + concept __decayed_same_as = same_as, decay_t<_Up>>; + class _Strong_order { template @@ -620,14 +623,12 @@ namespace std friend class _Strong_fallback; public: - template + template _Up> requires __strongly_ordered<_Tp, _Up> constexpr strong_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) { - static_assert(same_as, decay_t<_Up>>); - /* FIXME: if constexpr (floating_point>) return __cmp_cust::__fp_strong_order(__e, __f); @@ -669,14 +670,12 @@ namespace std friend class _Weak_fallback; public: - template + template _Up> requires __weakly_ordered<_Tp, _Up> constexpr weak_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) { - static_assert(same_as, decay_t<_Up>>); - if constexpr (floating_point>) return __cmp_cust::__fp_weak_ordering(__e, __f); else if constexpr (__adl_weak<_Tp, _Up>) @@ -716,14 +715,12 @@ namespace std friend class _Partial_fallback; public: - template + template _Up> requires __partially_ordered<_Tp, _Up> constexpr partial_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) { - static_assert(same_as, decay_t<_Up>>); - if constexpr (__adl_partial<_Tp, _Up>) return partial_ordering(partial_order(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f))); @@ -759,18 +756,16 @@ namespace std } public: - template + template _Up> requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up> - constexpr decltype(auto) + constexpr strong_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) { - static_assert(same_as, decay_t<_Up>>); - if constexpr (__strongly_ordered<_Tp, _Up>) return _Strong_order{}(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f)); - else if constexpr (__op_eq_lt<_Tp, _Up>) + else // __op_eq_lt<_Tp, _Up> return static_cast<_Tp&&>(__e) == static_cast<_Up&&>(__f) ? strong_ordering::equal : static_cast<_Tp&&>(__e) < static_cast<_Up&&>(__f) @@ -793,18 +788,16 @@ namespace std } public: - template + template _Up> requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up> - constexpr decltype(auto) + constexpr weak_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) { - static_assert(same_as, decay_t<_Up>>); - if constexpr (__weakly_ordered<_Tp, _Up>) return _Weak_order{}(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f)); - else if constexpr (__op_eq_lt<_Tp, _Up>) + else // __op_eq_lt<_Tp, _Up> return static_cast<_Tp&&>(__e) == static_cast<_Up&&>(__f) ? weak_ordering::equivalent : static_cast<_Tp&&>(__e) < static_cast<_Up&&>(__f) @@ -827,18 +820,16 @@ namespace std } public: - template + template _Up> requires __partially_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up> - constexpr decltype(auto) + constexpr partial_ordering operator()(_Tp&& __e, _Up&& __f) const noexcept(_S_noexcept<_Tp, _Up>()) { - static_assert(same_as, decay_t<_Up>>); - if constexpr (__partially_ordered<_Tp, _Up>) return _Partial_order{}(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f)); - else if constexpr (__op_eq_lt<_Tp, _Up>) + else // __op_eq_lt<_Tp, _Up> return static_cast<_Tp&&>(__e) == static_cast<_Up&&>(__f) ? partial_ordering::equivalent : static_cast<_Tp&&>(__e) < static_cast<_Up&&>(__f) diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc new file mode 100644 index 00000000000..ae458528f17 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +using std::strong_ordering; +using std::partial_ordering; + +namespace adl +{ + struct S { }; + void strong_ordering(const S&, const S&); + bool operator==(const S&, S&) { return true; } + bool operator<(const S&, S&) { return true; } +} + +template + concept has_strong_order_fallback = requires (T& t, U& u) { + std::compare_strong_order_fallback(t, u); + }; + +template + concept has_weak_order_fallback = requires (T& t, U& u) { + std::compare_weak_order_fallback(t, u); + }; + +template + concept has_partial_order_fallback = requires (T& t, U& u) { + std::compare_partial_order_fallback(t, u); + }; + +using adl::S; + +static_assert( has_strong_order_fallback ); +static_assert( has_strong_order_fallback ); +static_assert( ! has_strong_order_fallback ); +static_assert( has_weak_order_fallback ); +static_assert( has_weak_order_fallback ); +static_assert( ! has_weak_order_fallback ); +static_assert( has_partial_order_fallback ); +static_assert( has_partial_order_fallback ); +static_assert( ! has_partial_order_fallback ); --mnAOKjFTk4f0lNnv--