From cbf052dc5a940b310433345a82e0cab8ac88ea4a Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 17 Feb 2023 16:23:11 +0700 Subject: [PATCH 1/3] Implement LWG-3865 Sorting a range of `pair`s --- stl/inc/utility | 31 ++++++++++--------- .../test.cpp | 22 +++++++++++++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/stl/inc/utility b/stl/inc/utility index 0d420327631..d85d9b50898 100644 --- a/stl/inc/utility +++ b/stl/inc/utility @@ -480,15 +480,16 @@ constexpr void swap(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Righ } #endif // _HAS_CXX23 -_EXPORT_STD template -_NODISCARD constexpr bool operator==(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) { +_EXPORT_STD template +_NODISCARD constexpr bool operator==(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { return _Left.first == _Right.first && _Left.second == _Right.second; } #ifdef __cpp_lib_concepts -_EXPORT_STD template -_NODISCARD constexpr common_comparison_category_t<_Synth_three_way_result<_Ty1>, _Synth_three_way_result<_Ty2>> - operator<=>(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) { +_EXPORT_STD template +_NODISCARD constexpr common_comparison_category_t<_Synth_three_way_result<_Ty1, _Uty1>, + _Synth_three_way_result<_Ty2, _Uty1>> + operator<=>(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { if (auto _Result = _Synth_three_way{}(_Left.first, _Right.first); _Result != 0) { return _Result; } @@ -496,29 +497,29 @@ _NODISCARD constexpr common_comparison_category_t<_Synth_three_way_result<_Ty1>, } #else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv #if !_HAS_CXX20 -template -_NODISCARD constexpr bool operator!=(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) { +template +_NODISCARD constexpr bool operator!=(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { return !(_Left == _Right); } #endif // !_HAS_CXX20 -template -_NODISCARD constexpr bool operator<(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) { +template +_NODISCARD constexpr bool operator<(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { return _Left.first < _Right.first || (!(_Right.first < _Left.first) && _Left.second < _Right.second); } -template -_NODISCARD constexpr bool operator>(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) { +template +_NODISCARD constexpr bool operator>(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { return _Right < _Left; } -template -_NODISCARD constexpr bool operator<=(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) { +template +_NODISCARD constexpr bool operator<=(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { return !(_Right < _Left); } -template -_NODISCARD constexpr bool operator>=(const pair<_Ty1, _Ty2>& _Left, const pair<_Ty1, _Ty2>& _Right) { +template +_NODISCARD constexpr bool operator>=(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { return !(_Left < _Right); } #endif // ^^^ !defined(__cpp_lib_concepts) ^^^ diff --git a/tests/std/tests/Dev11_1140665_unique_ptr_array_conversions/test.cpp b/tests/std/tests/Dev11_1140665_unique_ptr_array_conversions/test.cpp index eebeebf7a6f..768f2d9204f 100644 --- a/tests/std/tests/Dev11_1140665_unique_ptr_array_conversions/test.cpp +++ b/tests/std/tests/Dev11_1140665_unique_ptr_array_conversions/test.cpp @@ -183,6 +183,25 @@ void my_swap(unique_ptr& lhs, unique_ptr& rhs) { swap(lhs, rhs); } +// also test LWG-3865 Sorting a range of pairs +constexpr bool test_lwg3865() { + const pair a{1, 2}; + const pair b{1, 2}; + const pair c{2, 2}; + assert(a == b); + assert(a != c); + assert(c >= a); + assert(b >= a); + assert(c > a); + assert(!(b > a)); + assert(a < c); + assert(!(a < b)); + assert(a <= c); + assert(a <= b); + + return true; +} + int main() { { assert(g_objects == 0); @@ -271,4 +290,7 @@ int main() { }; (void) make_unique[]>(42); } + + test_lwg3865(); + STATIC_ASSERT(test_lwg3865()); } From 4de66c7de5d42911abb55639ec01e0da454aa585 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 17 Feb 2023 16:54:44 +0700 Subject: [PATCH 2/3] typo --- stl/inc/utility | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/utility b/stl/inc/utility index d85d9b50898..35834b57111 100644 --- a/stl/inc/utility +++ b/stl/inc/utility @@ -488,7 +488,7 @@ _NODISCARD constexpr bool operator==(const pair<_Ty1, _Ty2>& _Left, const pair<_ #ifdef __cpp_lib_concepts _EXPORT_STD template _NODISCARD constexpr common_comparison_category_t<_Synth_three_way_result<_Ty1, _Uty1>, - _Synth_three_way_result<_Ty2, _Uty1>> + _Synth_three_way_result<_Ty2, _Uty2>> operator<=>(const pair<_Ty1, _Ty2>& _Left, const pair<_Uty1, _Uty2>& _Right) { if (auto _Result = _Synth_three_way{}(_Left.first, _Right.first); _Result != 0) { return _Result; From 4f2ec495a6b5e6ab61d504663b0ad7d3db9db547 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 17 Feb 2023 17:26:17 +0700 Subject: [PATCH 3/3] skip libc++ test --- tests/libcxx/expected_results.txt | 3 +++ tests/libcxx/skipped_tests.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index bb5eda0dd71..bf7e313b5a0 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -138,6 +138,9 @@ std/ranges/range.access/rbegin.pass.cpp FAIL std/ranges/range.access/rend.pass.cpp FAIL std/ranges/range.access/size.pass.cpp FAIL +# libc++ doesn't implement LWG-3865 Sorting a range of pairs +std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp FAIL + # *** INTERACTIONS WITH CONTEST / C1XX THAT UPSTREAM LIKELY WON'T FIX *** # Tracked by VSO-593630 " Enable libcxx filesystem tests" diff --git a/tests/libcxx/skipped_tests.txt b/tests/libcxx/skipped_tests.txt index f7cd2590acc..2072328948f 100644 --- a/tests/libcxx/skipped_tests.txt +++ b/tests/libcxx/skipped_tests.txt @@ -138,6 +138,9 @@ ranges\range.access\rbegin.pass.cpp ranges\range.access\rend.pass.cpp ranges\range.access\size.pass.cpp +# libc++ doesn't implement LWG-3865 Sorting a range of pairs +utilities\tuple\tuple.tuple\tuple.apply\make_from_tuple.pass.cpp + # *** INTERACTIONS WITH CONTEST / C1XX THAT UPSTREAM LIKELY WON'T FIX *** # Tracked by VSO-593630 " Enable libcxx filesystem tests"