From b2216ca690d7cceeb12673356146cd9f2366d8e9 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sat, 20 Jul 2024 20:09:59 +0200 Subject: [PATCH] CI fixes and improvements Note the code is not yet conforming. --- libcxx/include/__iterator/bounded_iter.h | 13 +++---- libcxx/include/__iterator/wrap_iter.h | 15 ++++---- libcxx/include/deque | 11 +++--- .../sequences/array/iterators.pass.cpp | 4 +-- .../sequences/deque/iterators.pass.cpp | 18 +++++++++- .../sequences/vector.bool/iterators.pass.cpp | 30 +++++++++++++++- .../sequences/vector/iterators.pass.cpp | 34 ++++++++++++++++++- .../span.iterators/iterator.pass.cpp | 4 ++- 8 files changed, 104 insertions(+), 25 deletions(-) diff --git a/libcxx/include/__iterator/bounded_iter.h b/libcxx/include/__iterator/bounded_iter.h index 10825043bf3bb23..755e5d5920c8574 100644 --- a/libcxx/include/__iterator/bounded_iter.h +++ b/libcxx/include/__iterator/bounded_iter.h @@ -12,7 +12,7 @@ #include <__assert> #include <__compare/ordering.h> -#include <__concepts/same_as.h> +#include <__compare/three_way_comparable.h> #include <__config> #include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> @@ -226,15 +226,10 @@ struct __bounded_iter { } #if _LIBCPP_STD_VER >= 20 - // It is not required that the underlying iterator supports operator<=>. - // Therefore this operator is only conditionally provided, which requires a - // templated function. - template - requires requires(_Iterator const& __i) { - { __i <=> __i } -> same_as; - } _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering - operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { + operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept + requires three_way_comparable<__bounded_iter, strong_ordering> + { return __x.__current_ <=> __y.__current_; } #endif // _LIBCPP_STD_VER >= 20 diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h index a181cbd7c726e5f..8462b0c82370081 100644 --- a/libcxx/include/__iterator/wrap_iter.h +++ b/libcxx/include/__iterator/wrap_iter.h @@ -11,6 +11,7 @@ #define _LIBCPP___ITERATOR_WRAP_ITER_H #include <__compare/ordering.h> +#include <__compare/three_way_comparable.h> #include <__config> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> @@ -120,8 +121,6 @@ operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX return __x.base() == __y.base(); } -#if _LIBCPP_STD_VER <= 17 - template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { @@ -182,21 +181,25 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX return !(__y < __x); } -#else // _LIBCPP_STD_VER <= 17 +#if _LIBCPP_STD_VER >= 20 template _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering -operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept { +operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept + requires three_way_comparable<_Iter1, strong_ordering> +{ return __x.base() <=> __y.base(); } template _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering -operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept { +operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept + requires three_way_comparable_with<_Iter1, _Iter2, strong_ordering> +{ return __x.base() <=> __y.base(); } -#endif // _LIBCPP_STD_VER <= 17 +#endif // _LIBCPP_STD_VER >= 20 template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 diff --git a/libcxx/include/deque b/libcxx/include/deque index ff4c93dae6147a7..782a9db79c7ae0f 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -376,7 +376,6 @@ public: return __x.__ptr_ == __y.__ptr_; } -#if _LIBCPP_STD_VER <= 17 _LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) { return !(__x == __y); } @@ -396,8 +395,12 @@ public: _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) { return !(__x < __y); } -#else // _LIBCPP_STD_VER <= 17 - _LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y) { + +#if _LIBCPP_STD_VER >= 20 + // template + _LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y) + requires three_way_comparable + { if (__x.__m_iter_ < __y.__m_iter_) return strong_ordering::less; @@ -406,7 +409,7 @@ public: return strong_ordering::greater; } -#endif // _LIBCPP_STD_VER <= 17 +#endif // _LIBCPP_STD_VER >= 20 private: _LIBCPP_HIDE_FROM_ABI explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT diff --git a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp index 9cbe3cb396c9ae2..710994c68295ef3 100644 --- a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp +++ b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp @@ -154,7 +154,7 @@ TEST_CONSTEXPR_CXX17 bool tests() std::same_as decltype(auto) r1 = ii1 <=> ii2; assert(r1 == std::strong_ordering::equal); - std::same_as decltype(auto) r2 = ii1 <=> ii2; + std::same_as decltype(auto) r2 = cii <=> ii2; assert(r2 == std::strong_ordering::equal); # endif } @@ -204,7 +204,7 @@ TEST_CONSTEXPR_CXX17 bool tests() std::same_as decltype(auto) r1 = ii1 <=> ii2; assert(r1 == std::strong_ordering::equal); - std::same_as decltype(auto) r2 = ii1 <=> ii2; + std::same_as decltype(auto) r2 = cii <=> ii2; assert(r2 == std::strong_ordering::equal); # endif } diff --git a/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp b/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp index a8b5db656b20574..396fd56dc641380 100644 --- a/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp +++ b/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp @@ -41,7 +41,23 @@ int main(int, char**) i = c.begin(); C::const_iterator j; j = c.cbegin(); + assert(i == j); + assert(!(i != j)); + + assert(!(i < j)); + assert((i <= j)); + + assert(!(i > j)); + assert((i >= j)); + +# if TEST_STD_VER >= 20 + // P1614 + LWG3352 + // When the allocator does not have operator<=> then neither does the iterator. + // Make sure to test with an allocator that does not have operator<=>. + static_assert(!std::three_way_comparable, std::strong_ordering>); + static_assert(!std::three_way_comparable); +# endif } #endif #if TEST_STD_VER > 11 @@ -80,7 +96,7 @@ int main(int, char**) std::same_as decltype(auto) r1 = ii1 <=> ii2; assert(r1 == std::strong_ordering::equal); - std::same_as decltype(auto) r2 = ii1 <=> ii2; + std::same_as decltype(auto) r2 = cii <=> ii2; assert(r2 == std::strong_ordering::equal); # endif // TEST_STD_VER > 20 } diff --git a/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp index 2a701cc4ad19fcd..1e4877e8d24430d 100644 --- a/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp @@ -77,7 +77,21 @@ TEST_CONSTEXPR_CXX20 bool tests() C::iterator i = c.begin(); C::iterator j = c.end(); assert(std::distance(i, j) == 0); + assert(i == j); + assert(!(i != j)); + + assert(!(i < j)); + assert((i <= j)); + + assert(!(i > j)); + assert((i >= j)); + +# if TEST_STD_VER >= 20 + // P1614 + LWG3352 + std::same_as decltype(auto) r = i <=> j; + assert(r == std::strong_ordering::equal); +# endif } { typedef bool T; @@ -86,7 +100,21 @@ TEST_CONSTEXPR_CXX20 bool tests() C::const_iterator i = c.begin(); C::const_iterator j = c.end(); assert(std::distance(i, j) == 0); + assert(i == j); + assert(!(i != j)); + + assert(!(i < j)); + assert((i <= j)); + + assert(!(i > j)); + assert((i >= j)); + +# if TEST_STD_VER >= 20 + // P1614 + LWG3352 + std::same_as decltype(auto) r = i <=> j; + assert(r == std::strong_ordering::equal); +# endif } { typedef bool T; @@ -137,7 +165,7 @@ TEST_CONSTEXPR_CXX20 bool tests() std::same_as decltype(auto) r1 = ii1 <=> ii2; assert(r1 == std::strong_ordering::equal); - std::same_as decltype(auto) r2 = ii1 <=> ii2; + std::same_as decltype(auto) r2 = cii <=> ii2; assert(r2 == std::strong_ordering::equal); # endif // TEST_STD_VER > 20 } diff --git a/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp b/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp index 457791b8ee6af6c..1d750cb1110f90f 100644 --- a/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp @@ -87,7 +87,23 @@ TEST_CONSTEXPR_CXX20 bool tests() C::iterator i = c.begin(); C::iterator j = c.end(); assert(std::distance(i, j) == 0); + assert(i == j); + assert(!(i != j)); + + assert(!(i < j)); + assert((i <= j)); + + assert(!(i > j)); + assert((i >= j)); + +# if TEST_STD_VER >= 20 + // P1614 + LWG3352 + // When the allocator does not have operator<=> then neither does the iterator. + // Make sure to test with an allocator that does not have operator<=>. + static_assert(!std::three_way_comparable, std::strong_ordering>); + static_assert(!std::three_way_comparable); +# endif } { typedef int T; @@ -96,7 +112,23 @@ TEST_CONSTEXPR_CXX20 bool tests() C::const_iterator i = c.begin(); C::const_iterator j = c.end(); assert(std::distance(i, j) == 0); + assert(i == j); + assert(!(i != j)); + + assert(!(i < j)); + assert((i <= j)); + + assert(!(i > j)); + assert((i >= j)); + +# if TEST_STD_VER >= 20 + // P1614 + LWG3352 + // When the allocator does not have operator<=> then neither does the iterator. + // Make sure to test with an allocator that does not have operator<=>. + static_assert(!std::three_way_comparable, std::strong_ordering>); + static_assert(!std::three_way_comparable); +# endif } { typedef int T; @@ -169,7 +201,7 @@ TEST_CONSTEXPR_CXX20 bool tests() std::same_as decltype(auto) r1 = ii1 <=> ii2; assert(r1 == std::strong_ordering::equal); - std::same_as decltype(auto) r2 = ii1 <=> ii2; + std::same_as decltype(auto) r2 = cii <=> ii2; assert(r2 == std::strong_ordering::equal); # endif // TEST_STD_VER > 20 } diff --git a/libcxx/test/std/containers/views/views.span/span.iterators/iterator.pass.cpp b/libcxx/test/std/containers/views/views.span/span.iterators/iterator.pass.cpp index 3d37267d61d63be..b097e4dc994a7c6 100644 --- a/libcxx/test/std/containers/views/views.span/span.iterators/iterator.pass.cpp +++ b/libcxx/test/std/containers/views/views.span/span.iterators/iterator.pass.cpp @@ -71,8 +71,10 @@ TEST_CONSTEXPR void test_type() { std::same_as decltype(auto) r1 = ii1 <=> ii2; assert(r1 == std::strong_ordering::equal); - std::same_as decltype(auto) r2 = ii1 <=> ii2; +#ifdef __cpp_lib_ranges_as_const + std::same_as decltype(auto) r2 = cii <=> ii2; assert(r2 == std::strong_ordering::equal); +#endif } TEST_CONSTEXPR bool test() {