diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv index 3809446a57896..99fc0b38077ab 100644 --- a/libcxx/docs/Status/Cxx2cPapers.csv +++ b/libcxx/docs/Status/Cxx2cPapers.csv @@ -59,7 +59,7 @@ "`P2248R8 `__","Enabling list-initialization for algorithms","2024-03 (Tokyo)","","","" "`P2810R4 `__","``is_debugger_present`` ``is_replaceable``","2024-03 (Tokyo)","","","" "`P1068R11 `__","Vector API for random number generation","2024-03 (Tokyo)","","","" -"`P2944R3 `__","Comparisons for ``reference_wrapper``","2024-03 (Tokyo)","|Partial|","","Implemented changes to ``reference_wrapper`` and ``pair``" +"`P2944R3 `__","Comparisons for ``reference_wrapper``","2024-03 (Tokyo)","|Partial|","","Not implemented ``tuple`` and ``variant``" "`P2642R6 `__","Padded ``mdspan`` layouts","2024-03 (Tokyo)","","","" "`P3029R1 `__","Better ``mdspan``'s CTAD","2024-03 (Tokyo)","|Complete|","19","" "","","","","","" diff --git a/libcxx/include/__functional/reference_wrapper.h b/libcxx/include/__functional/reference_wrapper.h index b409ad7511f6c..c46203a4ca9a4 100644 --- a/libcxx/include/__functional/reference_wrapper.h +++ b/libcxx/include/__functional/reference_wrapper.h @@ -11,7 +11,6 @@ #define _LIBCPP___FUNCTIONAL_REFERENCE_WRAPPER_H #include <__compare/synth_three_way.h> -#include <__concepts/boolean_testable.h> #include <__config> #include <__functional/weak_result_type.h> #include <__memory/addressof.h> @@ -19,6 +18,7 @@ #include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> #include <__type_traits/is_const.h> +#include <__type_traits/is_core_convertible.h> #include <__type_traits/remove_cvref.h> #include <__type_traits/void_t.h> #include <__utility/declval.h> @@ -75,7 +75,7 @@ class reference_wrapper : public __weak_result_type<_Tp> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y) requires requires { - { __x.get() == __y.get() } -> __boolean_testable; + { __x.get() == __y.get() } -> __core_convertible_to; } { return __x.get() == __y.get(); @@ -83,7 +83,7 @@ class reference_wrapper : public __weak_result_type<_Tp> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, const _Tp& __y) requires requires { - { __x.get() == __y } -> __boolean_testable; + { __x.get() == __y } -> __core_convertible_to; } { return __x.get() == __y; @@ -91,7 +91,7 @@ class reference_wrapper : public __weak_result_type<_Tp> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y) requires(!is_const_v<_Tp>) && requires { - { __x.get() == __y.get() } -> __boolean_testable; + { __x.get() == __y.get() } -> __core_convertible_to; } { return __x.get() == __y.get(); diff --git a/libcxx/include/optional b/libcxx/include/optional index 2153efb2ab899..059ca0156475b 100644 --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -205,6 +205,7 @@ namespace std { # include <__type_traits/is_assignable.h> # include <__type_traits/is_constructible.h> # include <__type_traits/is_convertible.h> +# include <__type_traits/is_core_convertible.h> # include <__type_traits/is_destructible.h> # include <__type_traits/is_nothrow_assignable.h> # include <__type_traits/is_nothrow_constructible.h> @@ -983,12 +984,23 @@ public: template optional(_Tp) -> optional<_Tp>; -// Comparisons between optionals +// [optional.relops] Relational operators + +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() == std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const optional<_Up>& __y) +# if _LIBCPP_STD_VER >= 26 + requires requires { + { *__x == *__y } -> __core_convertible_to; + } +# endif +{ if (static_cast(__x) != static_cast(__y)) return false; if (!static_cast(__x)) @@ -996,11 +1008,21 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const return *__x == *__y; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() != std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) +# if _LIBCPP_STD_VER >= 26 + requires requires { + { *__x != *__y } -> __core_convertible_to; + } +# endif +{ if (static_cast(__x) != static_cast(__y)) return true; if (!static_cast(__x)) @@ -1008,11 +1030,21 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const return *__x != *__y; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() < std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const optional<_Up>& __y) +# if _LIBCPP_STD_VER >= 26 + requires requires { + { *__x < *__y } -> __core_convertible_to; + } +# endif +{ if (!static_cast(__y)) return false; if (!static_cast(__x)) @@ -1020,11 +1052,21 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const o return *__x < *__y; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() > std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const optional<_Up>& __y) +# if _LIBCPP_STD_VER >= 26 + requires requires { + { *__x > *__y } -> __core_convertible_to; + } +# endif +{ if (!static_cast(__x)) return false; if (!static_cast(__y)) @@ -1032,11 +1074,21 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const o return *__x > *__y; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() <= std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) +# if _LIBCPP_STD_VER >= 26 + requires requires { + { *__x <= *__y } -> __core_convertible_to; + } +# endif +{ if (!static_cast(__x)) return true; if (!static_cast(__y)) @@ -1044,11 +1096,21 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const return *__x <= *__y; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() >= std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) +# if _LIBCPP_STD_VER >= 26 + requires requires { + { *__x >= *__y } -> __core_convertible_to; + } +# endif +{ if (!static_cast(__y)) return true; if (!static_cast(__x)) @@ -1068,7 +1130,8 @@ operator<=>(const optional<_Tp>& __x, const optional<_Up>& __y) { # endif // _LIBCPP_STD_VER >= 20 -// Comparisons with nullopt +// [optional.nullops] Comparison with nullopt + template _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, nullopt_t) noexcept { return !static_cast(__x); @@ -1140,100 +1203,221 @@ _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>& # endif // _LIBCPP_STD_VER <= 17 -// Comparisons with T +// [optional.comp.with.t] Comparison with T + +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() == std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const _Up& __v) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const _Up& __v) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Up>::value) && requires { + { *__x == __v } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? *__x == __v : false; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() == std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const _Tp& __v, const optional<_Up>& __x) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const _Tp& __v, const optional<_Up>& __x) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Tp>::value) && requires { + { __v == *__x } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? __v == *__x : false; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() != std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const _Up& __v) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const _Up& __v) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Up>::value) && requires { + { *__x != __v } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? *__x != __v : true; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() != std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const _Tp& __v, const optional<_Up>& __x) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const _Tp& __v, const optional<_Up>& __x) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Tp>::value) && requires { + { __v != *__x } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? __v != *__x : true; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() < std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const _Up& __v) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const _Up& __v) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Up>::value) && requires { + { *__x < __v } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? *__x < __v : true; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() < std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const _Tp& __v, const optional<_Up>& __x) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const _Tp& __v, const optional<_Up>& __x) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Tp>::value) && requires { + { __v < *__x } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? __v < *__x : false; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() <= std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const _Up& __v) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const _Up& __v) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Up>::value) && requires { + { *__x <= __v } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? *__x <= __v : true; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() <= std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const _Tp& __v, const optional<_Up>& __x) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const _Tp& __v, const optional<_Up>& __x) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Tp>::value) && requires { + { __v <= *__x } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? __v <= *__x : false; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() > std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const _Up& __v) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const _Up& __v) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Up>::value) && requires { + { *__x > __v } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? *__x > __v : false; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() > std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const _Tp& __v, const optional<_Up>& __x) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const _Tp& __v, const optional<_Up>& __x) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Tp>::value) && requires { + { __v > *__x } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? __v > *__x : true; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() >= std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const _Up& __v) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const _Up& __v) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Up>::value) && requires { + { *__x >= __v } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? *__x >= __v : false; } +# if _LIBCPP_STD_VER >= 26 +template < class _Tp, class _Up> +# else template < class _Tp, class _Up, enable_if_t() >= std::declval()), bool>, int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const _Tp& __v, const optional<_Up>& __x) { +# endif +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const _Tp& __v, const optional<_Up>& __x) +# if _LIBCPP_STD_VER >= 26 + requires(!__is_std_optional<_Tp>::value) && requires { + { __v >= *__x } -> __core_convertible_to; + } +# endif +{ return static_cast(__x) ? __v >= *__x : true; } diff --git a/libcxx/include/version b/libcxx/include/version index 77d97b93adc6c..3a173e30c47ae 100644 --- a/libcxx/include/version +++ b/libcxx/include/version @@ -80,8 +80,8 @@ __cpp_lib_constexpr_tuple 201811L __cpp_lib_constexpr_typeinfo 202106L __cpp_lib_constexpr_utility 201811L __cpp_lib_constexpr_vector 201907L -__cpp_lib_constrained_equality 202403L - +__cpp_lib_constrained_equality 202411L + __cpp_lib_containers_ranges 202202L @@ -545,7 +545,7 @@ __cpp_lib_void_t 201411L # if !defined(_LIBCPP_ABI_VCRUNTIME) # define __cpp_lib_constexpr_new 202406L # endif -// # define __cpp_lib_constrained_equality 202403L +// # define __cpp_lib_constrained_equality 202411L // # define __cpp_lib_copyable_function 202306L // # define __cpp_lib_debugging 202311L // # define __cpp_lib_default_template_type_for_algorithm_values 202403L diff --git a/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp b/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp index 01be1db73041b..671747f89a82e 100644 --- a/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp +++ b/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp @@ -26,7 +26,6 @@ constexpr std::size_t N{1}; static_assert(std::three_way_comparable>); // Thanks to SFINAE, the following is not a compiler error but returns `false` -struct NonComparable {}; static_assert(!std::three_way_comparable>); // Implementation detail of `test_sequence_container_array_spaceship` diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp index d58f726f66e2f..9c7a84f145dde 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/expected.version.compile.pass.cpp @@ -20,6 +20,10 @@ #if TEST_STD_VER < 14 +# ifdef __cpp_lib_constrained_equality +# error "__cpp_lib_constrained_equality should not be defined before c++26" +# endif + # ifdef __cpp_lib_expected # error "__cpp_lib_expected should not be defined before c++23" # endif @@ -30,6 +34,10 @@ #elif TEST_STD_VER == 14 +# ifdef __cpp_lib_constrained_equality +# error "__cpp_lib_constrained_equality should not be defined before c++26" +# endif + # ifdef __cpp_lib_expected # error "__cpp_lib_expected should not be defined before c++23" # endif @@ -40,6 +48,10 @@ #elif TEST_STD_VER == 17 +# ifdef __cpp_lib_constrained_equality +# error "__cpp_lib_constrained_equality should not be defined before c++26" +# endif + # ifdef __cpp_lib_expected # error "__cpp_lib_expected should not be defined before c++23" # endif @@ -50,6 +62,10 @@ #elif TEST_STD_VER == 20 +# ifdef __cpp_lib_constrained_equality +# error "__cpp_lib_constrained_equality should not be defined before c++26" +# endif + # ifdef __cpp_lib_expected # error "__cpp_lib_expected should not be defined before c++23" # endif @@ -60,6 +76,10 @@ #elif TEST_STD_VER == 23 +# ifdef __cpp_lib_constrained_equality +# error "__cpp_lib_constrained_equality should not be defined before c++26" +# endif + # ifndef __cpp_lib_expected # error "__cpp_lib_expected should be defined in c++23" # endif @@ -73,6 +93,19 @@ #elif TEST_STD_VER > 23 +# if !defined(_LIBCPP_VERSION) +# ifndef __cpp_lib_constrained_equality +# error "__cpp_lib_constrained_equality should be defined in c++26" +# endif +# if __cpp_lib_constrained_equality != 202411L +# error "__cpp_lib_constrained_equality should have the value 202411L in c++26" +# endif +# else +# ifdef __cpp_lib_constrained_equality +# error "__cpp_lib_constrained_equality should not be defined because it is unimplemented in libc++!" +# endif +# endif + # ifndef __cpp_lib_expected # error "__cpp_lib_expected should be defined in c++26" # endif diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/optional.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/optional.version.compile.pass.cpp index f8ff69f618777..32685972d6019 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/optional.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/optional.version.compile.pass.cpp @@ -123,8 +123,8 @@ # ifndef __cpp_lib_constrained_equality # error "__cpp_lib_constrained_equality should be defined in c++26" # endif -# if __cpp_lib_constrained_equality != 202403L -# error "__cpp_lib_constrained_equality should have the value 202403L in c++26" +# if __cpp_lib_constrained_equality != 202411L +# error "__cpp_lib_constrained_equality should have the value 202411L in c++26" # endif # else # ifdef __cpp_lib_constrained_equality diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/tuple.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/tuple.version.compile.pass.cpp index f4a2fd8b29f45..b583edfc43ad0 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/tuple.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/tuple.version.compile.pass.cpp @@ -274,8 +274,8 @@ # ifndef __cpp_lib_constrained_equality # error "__cpp_lib_constrained_equality should be defined in c++26" # endif -# if __cpp_lib_constrained_equality != 202403L -# error "__cpp_lib_constrained_equality should have the value 202403L in c++26" +# if __cpp_lib_constrained_equality != 202411L +# error "__cpp_lib_constrained_equality should have the value 202411L in c++26" # endif # else # ifdef __cpp_lib_constrained_equality diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/utility.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/utility.version.compile.pass.cpp index e0a83c7813b28..7dd3478576331 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/utility.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/utility.version.compile.pass.cpp @@ -405,8 +405,8 @@ # ifndef __cpp_lib_constrained_equality # error "__cpp_lib_constrained_equality should be defined in c++26" # endif -# if __cpp_lib_constrained_equality != 202403L -# error "__cpp_lib_constrained_equality should have the value 202403L in c++26" +# if __cpp_lib_constrained_equality != 202411L +# error "__cpp_lib_constrained_equality should have the value 202411L in c++26" # endif # else # ifdef __cpp_lib_constrained_equality diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/variant.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/variant.version.compile.pass.cpp index dc4af4d09f9e5..4a7b9f7431a81 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/variant.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/variant.version.compile.pass.cpp @@ -103,8 +103,8 @@ # ifndef __cpp_lib_constrained_equality # error "__cpp_lib_constrained_equality should be defined in c++26" # endif -# if __cpp_lib_constrained_equality != 202403L -# error "__cpp_lib_constrained_equality should have the value 202403L in c++26" +# if __cpp_lib_constrained_equality != 202411L +# error "__cpp_lib_constrained_equality should have the value 202411L in c++26" # endif # else # ifdef __cpp_lib_constrained_equality diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp index aa33a2788f1eb..400309b944a1d 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp @@ -6494,8 +6494,8 @@ # ifndef __cpp_lib_constrained_equality # error "__cpp_lib_constrained_equality should be defined in c++26" # endif -# if __cpp_lib_constrained_equality != 202403L -# error "__cpp_lib_constrained_equality should have the value 202403L in c++26" +# if __cpp_lib_constrained_equality != 202411L +# error "__cpp_lib_constrained_equality should have the value 202411L in c++26" # endif # else # ifdef __cpp_lib_constrained_equality diff --git a/libcxx/test/std/utilities/expected/expected.expected/equality/equality.T2.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/equality/equality.T2.pass.cpp index 25eb97a2df4d3..16c6986ae670e 100644 --- a/libcxx/test/std/utilities/expected/expected.expected/equality/equality.T2.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.expected/equality/equality.T2.pass.cpp @@ -16,14 +16,14 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" -#include "../../types.h" #if TEST_STD_VER >= 26 // https://wg21.link/P3379R0 -static_assert(CanCompare, int>); -static_assert(CanCompare, EqualityComparable>); -static_assert(!CanCompare, NonComparable>); +static_assert(HasOperatorEqual, int>); +static_assert(HasOperatorEqual, EqualityComparable>); +static_assert(!HasOperatorEqual, NonComparable>); #endif constexpr bool test() { diff --git a/libcxx/test/std/utilities/expected/expected.expected/equality/equality.other_expected.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/equality/equality.other_expected.pass.cpp index f0f549b6b7772..218f0c39740e5 100644 --- a/libcxx/test/std/utilities/expected/expected.expected/equality/equality.other_expected.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.expected/equality/equality.other_expected.pass.cpp @@ -17,26 +17,26 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" -#include "../../types.h" // Test constraint -static_assert(!CanCompare); +static_assert(!HasOperatorEqual); -static_assert(CanCompare, std::expected>); -static_assert(CanCompare, std::expected>); +static_assert(HasOperatorEqual, std::expected>); +static_assert(HasOperatorEqual, std::expected>); #if TEST_STD_VER >= 26 // https://wg21.link/P3379R0 -static_assert(!CanCompare, std::expected>); -static_assert(CanCompare, std::expected>); -static_assert(!CanCompare, std::expected>); -static_assert(!CanCompare, std::expected>); -static_assert(!CanCompare, std::expected>); -static_assert(!CanCompare, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); +static_assert(HasOperatorEqual, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); #else // Note this is true because other overloads in expected are unconstrained -static_assert(CanCompare, std::expected>); +static_assert(HasOperatorEqual, std::expected>); #endif constexpr bool test() { // x.has_value() && y.has_value() diff --git a/libcxx/test/std/utilities/expected/expected.expected/equality/equality.unexpected.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/equality/equality.unexpected.pass.cpp index 6c7d2f39514e7..153cbbddf3062 100644 --- a/libcxx/test/std/utilities/expected/expected.expected/equality/equality.unexpected.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.expected/equality/equality.unexpected.pass.cpp @@ -16,14 +16,14 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" -#include "../../types.h" #if TEST_STD_VER >= 26 // https://wg21.link/P3379R0 -static_assert(CanCompare, std::unexpected>); -static_assert(CanCompare, std::unexpected>); -static_assert(!CanCompare, std::unexpected>); +static_assert(HasOperatorEqual, std::unexpected>); +static_assert(HasOperatorEqual, std::unexpected>); +static_assert(!HasOperatorEqual, std::unexpected>); #endif constexpr bool test() { diff --git a/libcxx/test/std/utilities/expected/expected.void/equality/equality.other_expected.pass.cpp b/libcxx/test/std/utilities/expected/expected.void/equality/equality.other_expected.pass.cpp index b6c3d8deee644..af53d0c00f578 100644 --- a/libcxx/test/std/utilities/expected/expected.void/equality/equality.other_expected.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.void/equality/equality.other_expected.pass.cpp @@ -17,26 +17,26 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" -#include "../../types.h" struct Foo{}; -static_assert(!CanCompare); +static_assert(!HasOperatorEqual); -static_assert(CanCompare, std::expected>); -static_assert(CanCompare, std::expected>); +static_assert(HasOperatorEqual, std::expected>); +static_assert(HasOperatorEqual, std::expected>); #if TEST_STD_VER >= 26 // https://wg21.link/P3379R0 -static_assert(!CanCompare, std::expected>); -static_assert(CanCompare, std::expected>); -static_assert(CanCompare, std::expected>); -static_assert(!CanCompare, std::expected>); -static_assert(!CanCompare, std::expected>); -static_assert(!CanCompare, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); +static_assert(HasOperatorEqual, std::expected>); +static_assert(HasOperatorEqual, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); +static_assert(!HasOperatorEqual, std::expected>); #else // Note this is true because other overloads in expected are unconstrained -static_assert(CanCompare, std::expected>); +static_assert(HasOperatorEqual, std::expected>); #endif constexpr bool test() { diff --git a/libcxx/test/std/utilities/expected/expected.void/equality/equality.unexpected.pass.cpp b/libcxx/test/std/utilities/expected/expected.void/equality/equality.unexpected.pass.cpp index f37f38bb71512..8d040d2ab7c0a 100644 --- a/libcxx/test/std/utilities/expected/expected.void/equality/equality.unexpected.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.void/equality/equality.unexpected.pass.cpp @@ -16,14 +16,14 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" -#include "../../types.h" #if TEST_STD_VER >= 26 // https://wg21.link/P3379R0 -static_assert(CanCompare, std::unexpected>); -static_assert(CanCompare, std::unexpected>); -static_assert(!CanCompare, std::unexpected>); +static_assert(HasOperatorEqual, std::unexpected>); +static_assert(HasOperatorEqual, std::unexpected>); +static_assert(!HasOperatorEqual, std::unexpected>); #endif constexpr bool test() { diff --git a/libcxx/test/std/utilities/expected/types.h b/libcxx/test/std/utilities/expected/types.h index 11473ca3d97de..df73ebdfe495e 100644 --- a/libcxx/test/std/utilities/expected/types.h +++ b/libcxx/test/std/utilities/expected/types.h @@ -336,17 +336,4 @@ struct CheckForInvalidWrites : public CheckForInvalidWritesBase -concept CanCompare = requires(T1 t1, T2 t2) { t1 == t2; }; - #endif // TEST_STD_UTILITIES_EXPECTED_TYPES_H diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp index 85106c18ec35a..4a2ae963e3bdb 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,16 +23,13 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(HasSpaceshipOperatorWithInt>); -static_assert(HasSpaceshipOperatorWithInt>); -static_assert(HasSpaceshipOperatorWithInt>); +static_assert(HasOperatorSpaceship, int>); +static_assert(HasOperatorSpaceship, int>); +static_assert(HasOperatorSpaceship, int>); -static_assert(!HasSpaceshipOperatorWithInt>); +static_assert(!HasOperatorSpaceship, int>); // Test comparisons. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp index 794fac00de8a6..3d72459bc5a19 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -22,17 +22,13 @@ #include "test_comparisons.h" #include "test_macros.h" - -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::three_way_comparable>); -static_assert(std::three_way_comparable>); -static_assert(std::three_way_comparable>); +static_assert(HasOperatorSpaceship>); +static_assert(HasOperatorSpaceship>); +static_assert(HasOperatorSpaceship>); -static_assert(!std::three_way_comparable>); +static_assert(!HasOperatorSpaceship>); // Test comparisons. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp index 9b1302affa851..1ae22b4ac58e0 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,18 +23,15 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::three_way_comparable_with, const StrongOrder>); -static_assert(std::three_way_comparable_with, const WeakOrder>); -static_assert(std::three_way_comparable_with, const PartialOrder>); +static_assert(HasOperatorSpaceship, std::reference_wrapper>); +static_assert(HasOperatorSpaceship, std::reference_wrapper>); +static_assert(HasOperatorSpaceship, std::reference_wrapper>); -static_assert(!std::three_way_comparable_with, const NonComparable>); -static_assert(!std::three_way_comparable_with, const NonComparable>); -static_assert(!std::three_way_comparable_with, const NonComparable>); +static_assert(!HasOperatorSpaceship, std::reference_wrapper>); +static_assert(!HasOperatorSpaceship, std::reference_wrapper>); +static_assert(!HasOperatorSpaceship, std::reference_wrapper>); // Test comparisons. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp index 465326818f17c..316ff7c303315 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,14 +23,13 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(HasEqualityOperatorWithInt>); +static_assert(HasOperatorEqual>); +static_assert(HasOperatorEqual, int>); -static_assert(!HasEqualityOperatorWithInt>); +static_assert(!HasOperatorEqual>); +static_assert(!HasOperatorEqual, int>); // Test equality. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp index a50b530bbc6e1..70e79d399861a 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -22,14 +22,11 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::equality_comparable>); +static_assert(HasOperatorEqual>); -static_assert(!std::equality_comparable>); +static_assert(!HasOperatorEqual>); // Test equality. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp index 10f017742a87f..c68ad5c4aa527 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,16 +23,13 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::equality_comparable_with, - std::reference_wrapper>); +static_assert( + HasOperatorEqual, std::reference_wrapper>); -static_assert(!std::equality_comparable_with, - std::reference_wrapper>); +static_assert( + !HasOperatorEqual, std::reference_wrapper>); // Test equality. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_concepts.h b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_concepts.h deleted file mode 100644 index 2dbb304f8af63..0000000000000 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_concepts.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_CONCEPTS_H -#define TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_CONCEPTS_H - -#include -#include - -// Equality - -template -concept HasEqualityOperatorWithInt = requires(T t, int i) { - { t.get() == i } -> std::convertible_to; -}; - -// Spaceship - -template -concept BooleanTestableImpl = std::convertible_to; - -template -concept BooleanTestable = BooleanTestableImpl && requires(T&& t) { - { !std::forward(t) } -> BooleanTestableImpl; -}; - -template -concept HasSpaceshipOperatorWithInt = requires(T t, int i) { - { t < i } -> BooleanTestable; - { i < t } -> BooleanTestable; -}; - -#endif // TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_CONCEPTS_H diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_types.h b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_types.h deleted file mode 100644 index cf5e568dbf936..0000000000000 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_types.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_TYPES_H -#define TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_TYPES_H - -#include - -struct EqualityComparable { - constexpr EqualityComparable(int value) : value_{value} {}; - - friend constexpr bool operator==(const EqualityComparable&, const EqualityComparable&) noexcept = default; - - int value_; -}; - -static_assert(std::equality_comparable); -static_assert(EqualityComparable{94} == EqualityComparable{94}); -static_assert(EqualityComparable{94} != EqualityComparable{82}); - -struct NonComparable {}; - -static_assert(!std::three_way_comparable); - -#endif // TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_TYPES_H diff --git a/libcxx/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp index 0636da7bcdf23..54965b270dcce 100644 --- a/libcxx/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp @@ -14,8 +14,29 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. + +static_assert(HasOperatorEqual>); +static_assert(HasOperatorEqual>); +static_assert(HasOperatorEqual>); + +static_assert(!HasOperatorEqual>); +static_assert(!HasOperatorEqual>); + +static_assert(HasOperatorEqual, int>); +static_assert(HasOperatorEqual, int>); +static_assert(HasOperatorEqual, EqualityComparable>); + +static_assert(!HasOperatorEqual, NonComparable>); +static_assert(!HasOperatorEqual, NonComparable>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp b/libcxx/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp index 2010157a8d011..b63b85b000930 100644 --- a/libcxx/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp @@ -14,8 +14,28 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorGreaterThan, int>); +static_assert(HasOperatorGreaterThan, ThreeWayComparable>); + +static_assert(!HasOperatorGreaterThan, NonComparable>); +static_assert(!HasOperatorGreaterThan, NonComparable>); +static_assert(!HasOperatorGreaterThan, ThreeWayComparable>); + +static_assert(HasOperatorGreaterThan>); +static_assert(HasOperatorGreaterThan>); + +static_assert(!HasOperatorGreaterThan>); +static_assert(!HasOperatorGreaterThan>); +static_assert(!HasOperatorGreaterThan>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp index 2e1e9b9316111..bb1a8c551d3d5 100644 --- a/libcxx/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp @@ -14,8 +14,28 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorGreaterThanEqual, int>); +static_assert(HasOperatorGreaterThanEqual, ThreeWayComparable>); + +static_assert(!HasOperatorGreaterThanEqual, NonComparable>); +static_assert(!HasOperatorGreaterThanEqual, NonComparable>); +static_assert(!HasOperatorGreaterThanEqual, ThreeWayComparable>); + +static_assert(HasOperatorGreaterThanEqual>); +static_assert(HasOperatorGreaterThanEqual>); + +static_assert(!HasOperatorGreaterThanEqual>); +static_assert(!HasOperatorGreaterThanEqual>); +static_assert(!HasOperatorGreaterThanEqual>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp index 7026c24de5dbf..8b08ec3deea5a 100644 --- a/libcxx/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp @@ -14,8 +14,28 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorLessThanEqual, int>); +static_assert(HasOperatorLessThanEqual, ThreeWayComparable>); + +static_assert(!HasOperatorLessThanEqual, NonComparable>); +static_assert(!HasOperatorLessThanEqual, NonComparable>); +static_assert(!HasOperatorLessThanEqual, ThreeWayComparable>); + +static_assert(HasOperatorLessThanEqual>); +static_assert(HasOperatorLessThanEqual>); + +static_assert(!HasOperatorLessThanEqual>); +static_assert(!HasOperatorLessThanEqual>); +static_assert(!HasOperatorLessThanEqual>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp b/libcxx/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp index b3d98684ba20b..3ef23a3224520 100644 --- a/libcxx/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp @@ -14,8 +14,28 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorLessThan, int>); +static_assert(HasOperatorLessThan, ThreeWayComparable>); + +static_assert(!HasOperatorLessThan, NonComparable>); +static_assert(!HasOperatorLessThan, NonComparable>); +static_assert(!HasOperatorLessThan, ThreeWayComparable>); + +static_assert(HasOperatorLessThan>); +static_assert(HasOperatorLessThan>); + +static_assert(!HasOperatorLessThan>); +static_assert(!HasOperatorLessThan>); +static_assert(!HasOperatorLessThan>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp index 36bc526e763fe..97fb8ee447393 100644 --- a/libcxx/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp @@ -14,8 +14,29 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. + +static_assert(HasOperatorNotEqual>); +static_assert(HasOperatorNotEqual>); +static_assert(HasOperatorNotEqual>); + +static_assert(!HasOperatorNotEqual>); +static_assert(!HasOperatorNotEqual>); + +static_assert(HasOperatorNotEqual, int>); +static_assert(HasOperatorNotEqual, int>); +static_assert(HasOperatorNotEqual, EqualityComparable>); + +static_assert(!HasOperatorNotEqual, NonComparable>); +static_assert(!HasOperatorNotEqual, NonComparable>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.relops/equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.relops/equal.pass.cpp index 96bda6a5afa26..6915b604d4ef4 100644 --- a/libcxx/test/std/utilities/optional/optional.relops/equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.relops/equal.pass.cpp @@ -15,8 +15,22 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. + +static_assert(HasOperatorEqual>); +static_assert(HasOperatorEqual>); +static_assert(HasOperatorEqual, std::optional>); + +static_assert(!HasOperatorEqual>); +static_assert(!HasOperatorEqual, std::optional>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp index 399823c868b5e..d14e7df6abc80 100644 --- a/libcxx/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp @@ -13,8 +13,21 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorGreaterThanEqual>); +static_assert(HasOperatorGreaterThanEqual, std::optional>); + +static_assert(!HasOperatorGreaterThanEqual>); +static_assert(!HasOperatorGreaterThanEqual>); +static_assert(!HasOperatorGreaterThanEqual, std::optional>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.relops/greater_than.pass.cpp b/libcxx/test/std/utilities/optional/optional.relops/greater_than.pass.cpp index 6b877c3011cb0..f19ea23e8ae78 100644 --- a/libcxx/test/std/utilities/optional/optional.relops/greater_than.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.relops/greater_than.pass.cpp @@ -13,8 +13,21 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorGreaterThan>); +static_assert(HasOperatorGreaterThan, std::optional>); + +static_assert(!HasOperatorGreaterThan>); +static_assert(!HasOperatorGreaterThan>); +static_assert(!HasOperatorGreaterThan, std::optional>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.relops/less_equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.relops/less_equal.pass.cpp index aa605cd3a1e44..bd81a79f1265e 100644 --- a/libcxx/test/std/utilities/optional/optional.relops/less_equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.relops/less_equal.pass.cpp @@ -13,8 +13,21 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorLessThanEqual>); +static_assert(HasOperatorLessThanEqual, std::optional>); + +static_assert(!HasOperatorLessThanEqual>); +static_assert(!HasOperatorLessThanEqual>); +static_assert(!HasOperatorLessThanEqual, std::optional>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.relops/less_than.pass.cpp b/libcxx/test/std/utilities/optional/optional.relops/less_than.pass.cpp index 53474ebc5f0e9..c87bfd6f73e54 100644 --- a/libcxx/test/std/utilities/optional/optional.relops/less_than.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.relops/less_than.pass.cpp @@ -13,8 +13,21 @@ #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. +static_assert(HasOperatorLessThan>); +static_assert(HasOperatorLessThan, std::optional>); + +static_assert(!HasOperatorLessThan>); +static_assert(!HasOperatorLessThan>); +static_assert(!HasOperatorLessThan, std::optional>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/optional/optional.relops/not_equal.pass.cpp b/libcxx/test/std/utilities/optional/optional.relops/not_equal.pass.cpp index 290459d9ed090..1b7d2621c9193 100644 --- a/libcxx/test/std/utilities/optional/optional.relops/not_equal.pass.cpp +++ b/libcxx/test/std/utilities/optional/optional.relops/not_equal.pass.cpp @@ -15,8 +15,22 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" +#if TEST_STD_VER >= 26 + +// Test SFINAE. + +static_assert(HasOperatorNotEqual>); +static_assert(HasOperatorNotEqual>); +static_assert(HasOperatorNotEqual, std::optional>); + +static_assert(!HasOperatorNotEqual>); +static_assert(!HasOperatorNotEqual, std::optional>); + +#endif + using std::optional; struct X { diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp index c472906c5ed7f..226a3587a47f4 100644 --- a/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp @@ -21,28 +21,15 @@ #include #include +#include "test_comparisons.h" #include "test_macros.h" #if TEST_STD_VER >= 26 // Test SFINAE. -struct EqualityComparable { - constexpr EqualityComparable(int value) : value_{value} {}; - - friend constexpr bool operator==(const EqualityComparable&, const EqualityComparable&) noexcept = default; - - int value_; -}; - -static_assert(std::equality_comparable); - static_assert(std::equality_comparable>); -struct NonComparable {}; - -static_assert(!std::equality_comparable); - static_assert(!std::equality_comparable>); static_assert(!std::equality_comparable>); diff --git a/libcxx/test/support/test_comparisons.h b/libcxx/test/support/test_comparisons.h index db6977a96a2fe..e37ab44828c70 100644 --- a/libcxx/test/support/test_comparisons.h +++ b/libcxx/test/support/test_comparisons.h @@ -268,6 +268,70 @@ struct PartialOrder { } }; -#endif +template +concept HasOperatorEqual = requires(T1 t1, T2 t2) { t1 == t2; }; + +template +concept HasOperatorGreaterThan = requires(T1 t1, T2 t2) { t1 > t2; }; + +template +concept HasOperatorGreaterThanEqual = requires(T1 t1, T2 t2) { t1 >= t2; }; +template +concept HasOperatorLessThan = requires(T1 t1, T2 t2) { t1 < t2; }; + +template +concept HasOperatorLessThanEqual = requires(T1 t1, T2 t2) { t1 <= t2; }; + +template +concept HasOperatorNotEqual = requires(T1 t1, T2 t2) { t1 != t2; }; + +template +concept HasOperatorSpaceship = requires(T1 t1, T2 t2) { t1 <=> t2; }; + +struct NonComparable {}; +static_assert(!std::equality_comparable); +static_assert(!HasOperatorEqual); +static_assert(!HasOperatorGreaterThan); +static_assert(!HasOperatorGreaterThanEqual); +static_assert(!HasOperatorLessThan); +static_assert(!HasOperatorLessThanEqual); +static_assert(!HasOperatorNotEqual); +static_assert(!HasOperatorSpaceship); + +class EqualityComparable { +public: + constexpr EqualityComparable(int value) : value_{value} {}; + + friend constexpr bool operator==(const EqualityComparable&, const EqualityComparable&) noexcept = default; + +private: + int value_; +}; +static_assert(std::equality_comparable); +static_assert(HasOperatorEqual); +static_assert(HasOperatorNotEqual); + +class ThreeWayComparable { +public: + constexpr ThreeWayComparable(int value) : value_{value} {}; + + friend constexpr bool operator==(const ThreeWayComparable&, const ThreeWayComparable&) noexcept = default; + friend constexpr std::strong_ordering + operator<=>(const ThreeWayComparable&, const ThreeWayComparable&) noexcept = default; + +private: + int value_; +}; +static_assert(std::equality_comparable); +static_assert(std::three_way_comparable); +static_assert(HasOperatorEqual); +static_assert(HasOperatorGreaterThan); +static_assert(HasOperatorGreaterThanEqual); +static_assert(HasOperatorLessThan); +static_assert(HasOperatorLessThanEqual); +static_assert(HasOperatorNotEqual); +static_assert(HasOperatorSpaceship); + +#endif // TEST_STD_VER >= 20 #endif // TEST_COMPARISONS_H diff --git a/libcxx/test/support/test_container_comparisons.h b/libcxx/test/support/test_container_comparisons.h index f7bf78e48a1f8..53db5ba99ce47 100644 --- a/libcxx/test/support/test_container_comparisons.h +++ b/libcxx/test/support/test_container_comparisons.h @@ -88,7 +88,6 @@ constexpr bool test_sequence_container_spaceship() { std::weak_ordering>(); // Thanks to SFINAE, the following is not a compiler error but returns `false` - struct NonComparable {}; static_assert(!std::three_way_comparable>); return true; @@ -163,7 +162,6 @@ constexpr void test_sequence_container_adaptor_spaceship_with_type() { template