Skip to content

Commit 90d2ac2

Browse files
Avoid violating precondition of __bit_log2
1 parent 5d68c59 commit 90d2ac2

File tree

1 file changed

+12
-0
lines changed
  • libcxx/include/__algorithm

1 file changed

+12
-0
lines changed

libcxx/include/__algorithm/sort.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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*
951960
template <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

Comments
 (0)