[PATCH v2] libstdc++: implement constexpr memory algorithms
Giuseppe D'Angelo
giuseppe.dangelo@kdab.com
Wed Feb 26 15:32:22 GMT 2025
Hello,
On 25/02/2025 23:46, Jonathan Wakely wrote:
>> Maybe we can get away with unconditionally declaring this
>> _GLIBCXX26_CONSTEXPR? If the compiler doesn't support constexpr
>> placement new then the 'constexpr' would be silently dropped at
>> instantiation time. This would be in line with C++23 P2448R2 which
>> made it no longer IFNDR to declare a constexpr function template
>> for which no specialization is actually constexpr.
>
> Yeah, for internal functions that aren't ever compiled as C++98, we
> can often just make them constexpr. It will never be called during
> constant evaluation in C++20 or older, but that's usually fine.
>
> In this case though, would the placement new make it ill-formed in
> Clang 18, which didn't support P2448R2?
Yes, I had the same question. Cppreference says that Clang 17/18 have a
partial implementation of P2448, not sure what that means:
https://en.cppreference.com/w/cpp/23
A quick test shows that it seems happy with a placement new in a
constexpr function in C++17 mode, but I'm not positive it won't complain
in some other case.
So I'm going to leave these macros alone if you don't mind.
>> We typically call __is_constant_evaluated fully qualified (though I
>> don't remember why since it's not eligible for ADL?)
>
> I don't think we're consistent, and it's not necessary.
>
> But we could simplify things a little by doing:
>
> #if __glibcxx_raw_memory_algorithms >= 202411L // >= C++26
> if consteval {
> return std::__do_uninit_copy(__first, __last, __result);
> }
> #endif
>
> We don't need to use the __is_constant_evaluated() wrapper, or even
> the std::is_constant_evaluated() function, because this is C++26 code
> so we know 'if consteval' works. Clang supports it since version 14,
> which is too old to support any C++26 mode, so every Clang that
> supports -std=c++2c also supports 'if consteval'.
I'm not sure if the extra FTM check makes it more readable, but I guess
`if consteval` is strictly better than the wrappers, so I'll amend this way.
New patch is attached.
Thank you,
--
Giuseppe D'Angelo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-libstdc-implement-constexpr-memory-algorithms.patch
Type: text/x-patch
Size: 32671 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250226/505d1c58/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4244 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250226/505d1c58/attachment-0001.p7s>
More information about the Libstdc++
mailing list