From 242c1c878591713b55cc5dba37d29158d8654838 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 2 Dec 2025 10:14:45 +0800 Subject: [PATCH] Backport P2404R3 Move-Only Types For Comparison Concepts to C++20 --- stl/inc/compare | 7 +------ stl/inc/concepts | 9 +-------- stl/inc/yvals_core.h | 9 ++------- .../env.lst | 2 +- .../test.compile.pass.cpp | 4 +--- 5 files changed, 6 insertions(+), 25 deletions(-) diff --git a/stl/inc/compare b/stl/inc/compare index 12edfacf18e..b0187d55f49 100644 --- a/stl/inc/compare +++ b/stl/inc/compare @@ -309,12 +309,7 @@ concept three_way_comparable = _Half_equality_comparable<_Ty, _Ty> && _Half_orde _EXPORT_STD template concept three_way_comparable_with = - three_way_comparable<_Ty1, _Cat> && three_way_comparable<_Ty2, _Cat> -#if _HAS_CXX23 - && _Comparison_common_type_with<_Ty1, _Ty2> -#else // ^^^ _HAS_CXX23 / !_HAS_CXX23 vvv - && common_reference_with&, const remove_reference_t<_Ty2>&> -#endif // ^^^ !_HAS_CXX23 ^^^ + three_way_comparable<_Ty1, _Cat> && three_way_comparable<_Ty2, _Cat> && _Comparison_common_type_with<_Ty1, _Ty2> && three_way_comparable&, const remove_reference_t<_Ty2>&>, _Cat> && _Weakly_equality_comparable_with<_Ty1, _Ty2> && _Partially_ordered_with<_Ty1, _Ty2> && requires(const remove_reference_t<_Ty1>& __t, const remove_reference_t<_Ty2>& __u) { diff --git a/stl/inc/concepts b/stl/inc/concepts index 77e51a4220e..19ea811bd8b 100644 --- a/stl/inc/concepts +++ b/stl/inc/concepts @@ -192,7 +192,6 @@ concept _Weakly_equality_comparable_with = _EXPORT_STD template concept equality_comparable = _Half_equality_comparable<_Ty, _Ty>; -#if _HAS_CXX23 template > concept _Comparison_common_type_with_impl = same_as<_Ref, common_reference_t> && requires { requires convertible_to || convertible_to<_Ty1, const _Ref&>; @@ -201,16 +200,10 @@ concept _Comparison_common_type_with_impl = same_as<_Ref, common_reference_t concept _Comparison_common_type_with = _Comparison_common_type_with_impl, remove_cvref_t<_Ty2>>; -#endif // _HAS_CXX23 _EXPORT_STD template concept equality_comparable_with = - equality_comparable<_Ty1> && equality_comparable<_Ty2> -#if _HAS_CXX23 - && _Comparison_common_type_with<_Ty1, _Ty2> -#else // ^^^ _HAS_CXX23 / !_HAS_CXX23 vvv - && common_reference_with&, const remove_reference_t<_Ty2>&> -#endif // ^^^ !_HAS_CXX23 ^^^ + equality_comparable<_Ty1> && equality_comparable<_Ty2> && _Comparison_common_type_with<_Ty1, _Ty2> && equality_comparable&, const remove_reference_t<_Ty2>&>> && _Weakly_equality_comparable_with<_Ty1, _Ty2>; diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 558649b248b..337a70e8c12 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -292,6 +292,7 @@ // P2367R0 Remove Misuses Of List-Initialization From Clause 24 Ranges // P2372R3 Fixing Locale Handling In chrono Formatters // P2393R1 Cleaning Up Integer-Class Types +// P2404R3 Move-Only Types For Comparison Concepts // P2408R5 Ranges Iterators As Inputs To Non-Ranges Algorithms // P2415R2 What Is A view? // P2418R2 Add Support For std::generator-like Types To std::format @@ -365,7 +366,6 @@ // P2322R6 ranges::fold_left, ranges::fold_right, Etc. // P2374R4 views::cartesian_product // P2387R3 Pipe Support For User-Defined Range Adaptors -// P2404R3 Move-Only Types For Comparison Concepts // P2417R2 More constexpr bitset // P2438R2 string::substr() && // P2440R1 ranges::iota, ranges::shift_left, ranges::shift_right @@ -1681,6 +1681,7 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect #define __cpp_lib_bounded_array_traits 201902L #define __cpp_lib_common_reference 202302L #define __cpp_lib_common_reference_wrapper 202302L +#define __cpp_lib_concepts 202207L #define __cpp_lib_constexpr_algorithms 201806L #define __cpp_lib_constexpr_complex 201711L #define __cpp_lib_constexpr_dynamic_alloc 201907L @@ -1818,12 +1819,6 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect #define __cpp_lib_chrono 201510L // P0092R1 floor(), ceil(), round(), abs() #endif -#if _HAS_CXX23 -#define __cpp_lib_concepts 202207L // P2404R3 Move-Only Types For Comparison Concepts -#elif _HAS_CXX20 -#define __cpp_lib_concepts 202002L // P1964R2 Replacing boolean With boolean-testable -#endif - #if _HAS_CXX23 #define __cpp_lib_constexpr_memory 202202L // P2273R3 constexpr unique_ptr #elif _HAS_CXX20 diff --git a/tests/std/tests/P2404R3_move_only_types_for_comparison_concepts/env.lst b/tests/std/tests/P2404R3_move_only_types_for_comparison_concepts/env.lst index 642f530ffad..351a8293d9d 100644 --- a/tests/std/tests/P2404R3_move_only_types_for_comparison_concepts/env.lst +++ b/tests/std/tests/P2404R3_move_only_types_for_comparison_concepts/env.lst @@ -1,4 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\usual_latest_matrix.lst +RUNALL_INCLUDE ..\usual_20_matrix.lst diff --git a/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp b/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp index fe5fbd82a9a..3fe53dca792 100644 --- a/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp +++ b/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp @@ -197,10 +197,8 @@ STATIC_ASSERT(__cpp_lib_common_reference_wrapper == 202302L); STATIC_ASSERT(__cpp_lib_complex_udls == 201309L); -#if _HAS_CXX23 +#if _HAS_CXX20 STATIC_ASSERT(__cpp_lib_concepts == 202207L); -#elif _HAS_CXX20 -STATIC_ASSERT(__cpp_lib_concepts == 202002L); #elif defined(__cpp_lib_concepts) #error __cpp_lib_concepts is defined #endif