]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: add support for constexpr stable_sort (P2562R1)
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Tue, 25 Feb 2025 18:23:55 +0000 (18:23 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 25 Feb 2025 22:34:24 +0000 (22:34 +0000)
commitff43f9853d3b10e0d2694cd607da1056cb80f38a
treead583e7e2c4d4296752896813827cf15dcc4f228
parent6a30ffd759ba004c77c7e37520659e9ab0eb80cc
libstdc++: add support for constexpr stable_sort (P2562R1)

stable_sort has been made constexpr in C++26. Apart from plastering a
few functions with constexpr, there's an implementation challenge, that
is: stable_sort takes different codepaths in case extra memory can be
allocated. Rather than doing some major refactorings, simply use the
non-allocating path during constant evaluation. That's the same codepath
used when extra memory could not be allocated, as well as by
freestanding.

libstdc++-v3/ChangeLog:

* include/bits/algorithmfwd.h (stable_sort): Add constexpr.
* include/bits/ranges_algo.h (__stable_sort_fn): Add constexpr
to the function call operators.
* include/bits/stl_algo.h (__stable_sort): Add constexpr.
During constant evaluation, always use the non-allocating path.
(stable_sort): Add constexpr.
(__inplace_stable_sort): Likewise.
(__merge_without_buffer): Likewise.
* include/bits/version.def (constexpr_algorithms): Bump value
for C++26.
* include/bits/version.h: Regnerate.
* testsuite/25_algorithms/cpp_lib_constexpr.cc: Test the bumped
feature-testing macro.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Adapt
the test to constexpr stable_sort.
* testsuite/25_algorithms/stable_sort/constexpr.cc: New test.

Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
libstdc++-v3/include/bits/algorithmfwd.h
libstdc++-v3/include/bits/ranges_algo.h
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/testsuite/25_algorithms/cpp_lib_constexpr.cc
libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc
libstdc++-v3/testsuite/25_algorithms/stable_sort/constexpr.cc [new file with mode: 0644]