Author: Jordan Rupprecht Date: 2022-02-21T11:52:32-08:00 New Revision: c06cc1c3a7f8e20f6243433d3d15986d8758be30
URL: https://github.com/llvm/llvm-project/commit/c06cc1c3a7f8e20f6243433d3d15986d8758be30 DIFF: https://github.com/llvm/llvm-project/commit/c06cc1c3a7f8e20f6243433d3d15986d8758be30.diff LOG: [libc++] Fix std::__debug_less in c++17. b07b5bd72716625e0976a84d23652d94d8d0165a adds a use of `__comp_ref_type.h` to `std::min`. When libc++ is built with `-D_LIBCPP_DEBUG=0`, this enables `std::__debug_less`, which is only marked constexpr after c++17. `std::min` itself is marked as being `constexpr` as of c++14, so by extension, `std::__debug_less` should also be marked `constexpr` for the same versions so that `std::min` can use it. This change lowers the guard from `> 17` to `> 11`. Reproducer in godbolt: https://godbolt.org/z/ans3TGsj8 ``` constexpr int x() { return std::min<int>({1, 2, 3, 4}); } static_assert(x() == 1); ``` Reviewed By: #libc, philnik, Quuxplusone, ldionne Differential Revision: https://reviews.llvm.org/D118940 (cherry picked from commit 99e5c5256ff2eeebd977f2c82567f52b1e534a1f) Added: Modified: libcxx/include/__algorithm/comp_ref_type.h libcxx/test/libcxx/algorithms/debug_less.pass.cpp Removed: ################################################################################ diff --git a/libcxx/include/__algorithm/comp_ref_type.h b/libcxx/include/__algorithm/comp_ref_type.h index 6cc6405686f5d..0802d2496f5c0 100644 --- a/libcxx/include/__algorithm/comp_ref_type.h +++ b/libcxx/include/__algorithm/comp_ref_type.h @@ -28,11 +28,11 @@ template <class _Compare> struct __debug_less { _Compare &__comp_; - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 __debug_less(_Compare& __c) : __comp_(__c) {} template <class _Tp, class _Up> - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp& __x, const _Up& __y) { bool __r = __comp_(__x, __y); @@ -42,7 +42,7 @@ struct __debug_less } template <class _Tp, class _Up> - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(_Tp& __x, _Up& __y) { bool __r = __comp_(__x, __y); @@ -52,7 +52,7 @@ struct __debug_less } template <class _LHS, class _RHS> - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 inline _LIBCPP_INLINE_VISIBILITY decltype((void)declval<_Compare&>()( declval<_LHS &>(), declval<_RHS &>())) @@ -62,7 +62,7 @@ struct __debug_less } template <class _LHS, class _RHS> - _LIBCPP_CONSTEXPR_AFTER_CXX17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 inline _LIBCPP_INLINE_VISIBILITY void __do_compare_assert(long, _LHS &, _RHS &) {} }; diff --git a/libcxx/test/libcxx/algorithms/debug_less.pass.cpp b/libcxx/test/libcxx/algorithms/debug_less.pass.cpp index 6dd56955001d0..46735cd31c5cf 100644 --- a/libcxx/test/libcxx/algorithms/debug_less.pass.cpp +++ b/libcxx/test/libcxx/algorithms/debug_less.pass.cpp @@ -270,7 +270,7 @@ void test_value_categories() { assert(dl(static_cast<int&&>(1), static_cast<const int&&>(2))); } -#if TEST_STD_VER > 17 +#if TEST_STD_VER > 11 constexpr bool test_constexpr() { std::less<> cmp{}; __debug_less<std::less<> > dcmp(cmp); @@ -287,7 +287,7 @@ int main(int, char**) { test_non_const_arg_cmp(); test_value_iterator(); test_value_categories(); -#if TEST_STD_VER > 17 +#if TEST_STD_VER > 11 static_assert(test_constexpr(), ""); #endif return 0; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
