On 26/02/25 17:27 +0100, Giuseppe D'Angelo wrote:
On 26/02/2025 16:33, Giuseppe D'Angelo wrote:
Whops, sorry, missed this sub-thread (while replying to the other one).
Change of plans then, I'll amend and remove the ad-hoc constexpr macro.

Done, v3 attached.

Thanks,
--
Giuseppe D'Angelo


From de3751a38330f508be9f08b77136a31481018828 Mon Sep 17 00:00:00 2001
From: Giuseppe D'Angelo <giuseppe.dang...@kdab.com>
Date: Sun, 16 Feb 2025 19:37:07 +0100
Subject: [PATCH] libstdc++: implement constexpr memory algorithms

This commit adds support for C++26's constexpr specialized memory
algorithms, introduced by P2283R2, P3508R0, P3369R0.

The uninitialized_default, value, copy, move and fill algorithms are
affected, in all of their variants (iterator-based, range-based and _n
versions.)

The changes are mostly mechanical -- add `constexpr` to a number of
signatures when compiling in C++26 and above modes. The internal helper
guard class for range algorithms instead can be marked unconditionally.

The only "real" change to the implementation of the algorithms is that
during constant evaluation I need to dispatch to a constexpr-friendly
version of them.

For each algorithm family I've added only one test to cover it and its
variants; the idea is to avoid too much repetition and simplify future
maintenance.

The patch itself looks good, but I have some comments on the ChangeLog
part. These are thigns I would have tweaked myself before pushing, but
now that you have commit access ...

libstdc++-v3/ChangeLog:

        * include/bits/ranges_uninitialized.h: Mark the specialized
        memory algorithms as constexpr in C++26. Also mark the members
        of the _DestroyGuard helper class.
        * include/bits/stl_uninitialized.h: Ditto.
        * include/bits/stl_construct.h: Mark _Construct_novalue (which
        uses placement new to do default initialization) as constexpr
        in C++26. This is possible due to P2747R2, which GCC already
        implements; other compilers in C++26 modes already implement
        P2448R2, so there should be no issues there.

Per-file ChangeLog entries should say "what, not why" ... for reasons.
That makes old GNU-style ChangeLog files sometimes not very useful.
But at least we now have Git commit messages where we can put all the
detailed background, rationale etc.

So the explanation that it's possible to make it constexpr due to
P2448R2 should be above in the free text part of the commit message
above, along with the parenthesis saying what the function does.

Also, please mention the changed function by name, i.e.

        * include/bits/stl_construct.h (_Construct_novalue): Mark
        constexpr for C++26.

See
https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html
for the format.

For the changes in ranges_uninitialized.h and stl_uninitialized.h it's
basically "all the functions" so I think it's OK not to name them all.
(It would also be OK if you did name them all individually, but I
don't think it's necessary.)

        * include/bits/version.def: Bump the feature-testing macro.

Please mention which macro, e.g. something like:

        * include/bits/version.def (raw_memory_algorithms): Bump
        value.

        * include/bits/version.h: Regenerate.

(No need to mention the specific macro by name here, because the whole
file was regenerated so this is fine.)

        * testsuite/20_util/specialized_algorithms/feature_test_macro.cc: New 
test.

Please add a line break after the colon here (and the lines below). We
try to keep ChangeLog entries below about 78 columns, but for
libstdc++ tests that's often impossible because the pathname is
already longer than that! But we can still put the "New test." on a
new line.

Feel free to push to trunk with those changes to the ChangeLog lines
(and add Reviewed-by: tags for me and/or Patrick if you like). If
you'd feel more comfortable sending it to the mailing list again for a
final check, that's fine too.

Either way, the traditional first commit when you've got write after
approval access is to add yourself to the MAINTAINERS file, as per:
https://gcc.gnu.org/gitwrite.html#authenticated
If you add yourself to the DCO section at the end of the file, you can
omit the Signed-off-by: line in future commit messages (it's implied
if your name is in that section of the MAINTAINERS file).


        * 
testsuite/20_util/specialized_algorithms/uninitialized_copy/constexpr.cc: New 
test.
        * 
testsuite/20_util/specialized_algorithms/uninitialized_default_construct/constexpr.cc:
        New test.
        * 
testsuite/20_util/specialized_algorithms/uninitialized_fill/constexpr.cc: New 
test.
        * 
testsuite/20_util/specialized_algorithms/uninitialized_move/constexpr.cc: New 
test.
        * 
testsuite/20_util/specialized_algorithms/uninitialized_value_construct/constexpr.cc:
        New test.

Signed-off-by: Giuseppe D'Angelo <giuseppe.dang...@kdab.com>
---
.../include/bits/ranges_uninitialized.h       | 21 ++++++
libstdc++-v3/include/bits/stl_construct.h     |  1 +
libstdc++-v3/include/bits/stl_uninitialized.h | 39 +++++++++++
libstdc++-v3/include/bits/version.def         |  5 ++
libstdc++-v3/include/bits/version.h           |  7 +-
.../feature_test_macro.cc                     | 14 ++++
.../uninitialized_copy/constexpr.cc           | 58 ++++++++++++++++
.../constexpr.cc                              | 67 ++++++++++++++++++
.../uninitialized_fill/constexpr.cc           | 68 +++++++++++++++++++
.../uninitialized_move/constexpr.cc           | 51 ++++++++++++++
.../constexpr.cc                              | 64 +++++++++++++++++
11 files changed, 394 insertions(+), 1 deletion(-)
create mode 100644 
libstdc++-v3/testsuite/20_util/specialized_algorithms/feature_test_macro.cc
create mode 100644 
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/constexpr.cc
create mode 100644 
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_construct/constexpr.cc
create mode 100644 
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/constexpr.cc
create mode 100644 
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constexpr.cc
create mode 100644 
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct/constexpr.cc


Reply via email to