https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116341
Bug ID: 116341 Summary: out_of_range will occour in ranges::sort Product: gcc Version: 14.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: hdifhd at qq dot com Target Milestone: --- Hello guys, with the help of khjj (a9618994...@gmail.com). We thought that we had found a bug in 'std::ranges::sort' algorithm. Here is the demo: https://godbolt.org/z/9f7vK6E7e And we think this can make it right: diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 541f588883b..5e457f00dde 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -1814,8 +1814,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) if (__last - __first > int(_S_threshold)) { std::__insertion_sort(__first, __first + int(_S_threshold), __comp); - std::__unguarded_insertion_sort(__first + int(_S_threshold), __last, - __comp); + std::__insertion_sort(__first + int(_S_threshold), __last, __comp); } else std::__insertion_sort(__first, __last, __comp); But it is so slow, maybe there are better way to fix that?