From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 400893A6EC09; Wed, 17 Jun 2020 20:20:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 400893A6EC09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592425254; bh=XZCORUSpWm2PB+1mcvegKDBitL4YVE6rHtzgvs2l+bM=; h=From:To:Subject:Date:From; b=FLEftP44xABNAgWhAIjX1IaNTZq+q88Ridi4g++oIVaEjvxnCsP0lgIxWQEMCtFDw iA7rSwp6uI6ek3kYpGnyGheHZFdebHnkSkJi1tJx6RaqbrWtvn7zBnlpUXLdqLmNUy /80UACbbV7qURmEGdWj210TenFRhNt7ZAgTFjels= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/ranger] libstdc++: Implement LWG 3324 for [cmp.alg] function objects (LWG 3324) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/devel/ranger X-Git-Oldrev: 5b074864f8c593fd4bccee788a023a37b446b2ed X-Git-Newrev: 3fd1c229ad10fda68318882329568f400a38fb6d Message-Id: <20200617202054.400893A6EC09@sourceware.org> Date: Wed, 17 Jun 2020 20:20:54 +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: Wed, 17 Jun 2020 20:20:54 -0000 https://gcc.gnu.org/g:3fd1c229ad10fda68318882329568f400a38fb6d commit 3fd1c229ad10fda68318882329568f400a38fb6d Author: Jonathan Wakely Date: Thu Apr 9 22:24:57 2020 +0100 libstdc++: Implement LWG 3324 for [cmp.alg] function objects (LWG 3324) LWG 3324 changed the [cmp.alg] types to use std::compare_three_way instead of the <=> operator, but we were still using the old specification. In order to make the existing tests pass the N::X type needs to be equality comparable, so that three_way_comparable is satisfied and compare_three_way can be used. As part of this change I noticed that the compare_three_way call operator was unconditionally noexcept, which is incorrect. * libsupc++/compare (compare_three_way): Fix noexcept-specifier. (strong_order, weak_order, partial_order): Replace uses of <=> with compare_three_way function object (LWG 3324). * testsuite/18_support/comparisons/algorithms/partial_order.cc: Add equality operator so that X satisfies three_way_comparable. * testsuite/18_support/comparisons/algorithms/strong_order.cc: Likewise. * testsuite/18_support/comparisons/algorithms/weak_order.cc: Likewise. Diff: --- libstdc++-v3/ChangeLog | 9 ++++ libstdc++-v3/libsupc++/compare | 49 +++++++++++++--------- .../comparisons/algorithms/partial_order.cc | 4 ++ .../comparisons/algorithms/strong_order.cc | 4 ++ .../comparisons/algorithms/weak_order.cc | 4 ++ 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 98812f0faae..3ca7a0e7165 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2020-04-09 Jonathan Wakely + * libsupc++/compare (compare_three_way): Fix noexcept-specifier. + (strong_order, weak_order, partial_order): Replace uses of <=> with + compare_three_way function object (LWG 3324). + * testsuite/18_support/comparisons/algorithms/partial_order.cc: Add + equality operator so that X satisfies three_way_comparable. + * testsuite/18_support/comparisons/algorithms/strong_order.cc: + Likewise. + * testsuite/18_support/comparisons/algorithms/weak_order.cc: Likewise. + * include/bits/unique_ptr.h (operator<=>): Define for C++20. * testsuite/20_util/default_delete/48631_neg.cc: Adjust dg-error line. * testsuite/20_util/default_delete/void_neg.cc: Likewise. diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index b88b691b9e1..37601d32648 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -419,7 +419,8 @@ namespace std = __detail::__weakly_eq_cmp_with<_Tp, _Tp> && __detail::__partially_ordered_with<_Tp, _Tp> && requires(const remove_reference_t<_Tp>& __a, - const remove_reference_t<_Tp>& __b) { + const remove_reference_t<_Tp>& __b) + { { __a <=> __b } -> __detail::__compares_as<_Cat>; }; @@ -435,7 +436,8 @@ namespace std && __detail::__weakly_eq_cmp_with<_Tp, _Up> && __detail::__partially_ordered_with<_Tp, _Up> && requires(const remove_reference_t<_Tp>& __t, - const remove_reference_t<_Up>& __u) { + const remove_reference_t<_Up>& __u) + { { __t <=> __u } -> __detail::__compares_as<_Cat>; { __u <=> __t } -> __detail::__compares_as<_Cat>; }; @@ -494,7 +496,8 @@ namespace std template requires three_way_comparable_with<_Tp, _Up> constexpr auto - operator()(_Tp&& __t, _Up&& __u) const noexcept + operator()(_Tp&& __t, _Up&& __u) const + noexcept(noexcept(std::declval<_Tp>() <=> std::declval<_Up>())) { if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>) { @@ -579,16 +582,16 @@ namespace std }; template - concept __op_cmp = requires(_Tp&& __t, _Up&& __u) + concept __cmp3way = requires(_Tp&& __t, _Up&& __u, compare_three_way __c) { - _Ord(static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u)); + _Ord(__c(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u))); }; template concept __strongly_ordered = __adl_strong<_Tp, _Up> // FIXME: || floating_point> - || __op_cmp; + || __cmp3way; class _Strong_order { @@ -601,8 +604,9 @@ namespace std else if constexpr (__adl_strong<_Tp, _Up>) return noexcept(strong_ordering(strong_order(std::declval<_Tp>(), std::declval<_Up>()))); - else if constexpr (__op_cmp) - return noexcept(std::declval<_Tp>() <=> std::declval<_Up>()); + else if constexpr (__cmp3way) + return noexcept(compare_three_way()(std::declval<_Tp>(), + std::declval<_Up>())); } friend class _Weak_order; @@ -623,8 +627,9 @@ namespace std else */ if constexpr (__adl_strong<_Tp, _Up>) return strong_ordering(strong_order(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f))); - else if constexpr (__op_cmp) - return static_cast<_Tp&&>(__e) <=> static_cast<_Up&&>(__f); + else if constexpr (__cmp3way) + return compare_three_way()(static_cast<_Tp&&>(__e), + static_cast<_Up&&>(__f)); } }; @@ -632,7 +637,7 @@ namespace std concept __weakly_ordered = floating_point> || __adl_weak<_Tp, _Up> - || __op_cmp + || __cmp3way || __strongly_ordered<_Tp, _Up>; class _Weak_order @@ -646,8 +651,9 @@ namespace std else if constexpr (__adl_weak<_Tp, _Up>) return noexcept(weak_ordering(weak_order(std::declval<_Tp>(), std::declval<_Up>()))); - else if constexpr (__op_cmp) - return noexcept(std::declval<_Tp>() <=> std::declval<_Up>()); + else if constexpr (__cmp3way) + return noexcept(compare_three_way()(std::declval<_Tp>(), + std::declval<_Up>())); else if constexpr (__strongly_ordered<_Tp, _Up>) return _Strong_order::_S_noexcept<_Tp, _Up>(); } @@ -669,8 +675,9 @@ namespace std else if constexpr (__adl_weak<_Tp, _Up>) return weak_ordering(weak_order(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f))); - else if constexpr (__op_cmp) - return static_cast<_Tp&&>(__e) <=> static_cast<_Up&&>(__f); + else if constexpr (__cmp3way) + return compare_three_way()(static_cast<_Tp&&>(__e), + static_cast<_Up&&>(__f)); else if constexpr (__strongly_ordered<_Tp, _Up>) return _Strong_order{}(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f)); @@ -680,7 +687,7 @@ namespace std template concept __partially_ordered = __adl_partial<_Tp, _Up> - || __op_cmp + || __cmp3way || __weakly_ordered<_Tp, _Up>; class _Partial_order @@ -692,8 +699,9 @@ namespace std if constexpr (__adl_partial<_Tp, _Up>) return noexcept(partial_ordering(partial_order(std::declval<_Tp>(), std::declval<_Up>()))); - else if constexpr (__op_cmp) - return noexcept(std::declval<_Tp>() <=> std::declval<_Up>()); + else if constexpr (__cmp3way) + return noexcept(compare_three_way()(std::declval<_Tp>(), + std::declval<_Up>())); else if constexpr (__weakly_ordered<_Tp, _Up>) return _Weak_order::_S_noexcept<_Tp, _Up>(); } @@ -712,8 +720,9 @@ namespace std if constexpr (__adl_partial<_Tp, _Up>) return partial_ordering(partial_order(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f))); - else if constexpr (__op_cmp) - return static_cast<_Tp&&>(__e) <=> static_cast<_Up&&>(__f); + else if constexpr (__cmp3way) + return compare_three_way()(static_cast<_Tp&&>(__e), + static_cast<_Up&&>(__f)); else if constexpr (__weakly_ordered<_Tp, _Up>) return _Weak_order{}(static_cast<_Tp&&>(__e), static_cast<_Up&&>(__f)); diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc index aef738d538a..0806eabf74a 100644 --- a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc +++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc @@ -94,6 +94,10 @@ namespace N return partial_ordering::equivalent; return r.i <=> l.i; } + + constexpr bool operator==(X l, X r) { return std::is_eq(l <=> r); } + + static_assert(std::three_way_comparable); } void diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/strong_order.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/strong_order.cc index fd0a10c1f56..edbcc9f1acb 100644 --- a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/strong_order.cc +++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/strong_order.cc @@ -47,6 +47,10 @@ namespace N return strong_ordering::equivalent; return r.i <=> l.i; } + + constexpr bool operator==(X l, X r) { return std::is_eq(l <=> r); } + + static_assert(std::three_way_comparable); } using N::X; diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc index a5405dbc377..d7d43ade8d2 100644 --- a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc +++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc @@ -95,6 +95,10 @@ namespace N return weak_ordering::equivalent; return r.i <=> l.i; } + + constexpr bool operator==(X l, X r) { return std::is_eq(l <=> r); } + + static_assert(std::three_way_comparable); } void