@@ -904,6 +904,9 @@ template <class _AlgPolicy, class _Type, __enable_if_t<__sort_is_specialized_in_
904904_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __sort_dispatch (_Type* __first, _Type* __last, __less<>&) {
905905#if _LIBCPP_STD_VER >= 20
906906 if (std::is_constant_evaluated ()) {
907+ if (__last == first)
908+ return ;
909+
907910 auto __depth_limit = static_cast <ptrdiff_t >(2 * std::__bit_log2 (static_cast <size_t >(__last - __first)));
908911 std::__introsort<_ClassicAlgPolicy, ranges::less, _Type*, __use_branchless_sort<ranges::less, _Type*>>(
909912 __first, __last, ranges::less{}, __depth_limit);
@@ -919,6 +922,9 @@ template <class _AlgPolicy, class _Type, __enable_if_t<__sort_is_specialized_in_
919922_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __sort_dispatch (_Type* __first, _Type* __last, less<_Type>&) {
920923#if _LIBCPP_STD_VER >= 20
921924 if (std::is_constant_evaluated ()) {
925+ if (__last == first)
926+ return ;
927+
922928 auto __depth_limit = static_cast <ptrdiff_t >(2 * std::__bit_log2 (static_cast <size_t >(__last - __first)));
923929 std::__introsort<_ClassicAlgPolicy, ranges::less, _Type*, __use_branchless_sort<ranges::less, _Type*>>(
924930 __first, __last, ranges::less{}, __depth_limit);
@@ -935,6 +941,9 @@ template <class _AlgPolicy, class _Type, __enable_if_t<__sort_is_specialized_in_
935941_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __sort_dispatch (_Type* __first, _Type* __last, less<>&) {
936942# if _LIBCPP_STD_VER >= 20
937943 if (std::is_constant_evaluated ()) {
944+ if (__last == first)
945+ return ;
946+
938947 auto __depth_limit = static_cast <ptrdiff_t >(2 * std::__bit_log2 (static_cast <size_t >(__last - __first)));
939948 std::__introsort<_ClassicAlgPolicy, ranges::less, _Type*, __use_branchless_sort<ranges::less, _Type*>>(
940949 __first, __last, ranges::less{}, __depth_limit);
@@ -951,6 +960,9 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __sort_dispatch(_Type*
951960template <class _AlgPolicy , class _Type , __enable_if_t <__sort_is_specialized_in_library<_Type>::value, int > = 0 >
952961_LIBCPP_HIDE_FROM_ABI constexpr void __sort_dispatch (_Type* __first, _Type* __last, ranges::less&) {
953962 if (std::is_constant_evaluated ()) {
963+ if (__last == first)
964+ return ;
965+
954966 auto __depth_limit = static_cast <ptrdiff_t >(2 * std::__bit_log2 (static_cast <size_t >(__last - __first)));
955967 std::__introsort<_ClassicAlgPolicy, ranges::less, _Type*, __use_branchless_sort<ranges::less, _Type*>>(
956968 __first, __last, ranges::less{}, __depth_limit);
0 commit comments