c++, libstdc++: (Partially) Implement C++23 P0553: constexpr std::div()

PaulXiCao paulxicao7@gmail.com
Sun Aug 11 13:20:58 GMT 2024


Hi!

This patch makes std::div() constexpr. It is part of C++23, paper [P0553](
https://wg21.link/p0533).

The previous implementation dispatched to the libc's implementation (which
is not constexpr).
I reimplemented it to be uniform across all standards (e.g. fewer ifdefs).
The code has also been formatted s.t. all implementation details for
std::div() are closer together in code (i.e. appended to the file in one
block).

There is still an issue to fix: The c header `c_compatibility/stdlib.h`
should implement the c functions div().
I believe those cannot have the constexpr attribute which is why a
simple `using
std::div;` no longer works.

Development branch can be viewed here:
https://github.com/PaulXiCao/gcc/tree/constexprCmath_div .

# Description
P0553 was included in C++23 and mandates multiple math functions to be
`constexpr`.
This patch changes `std::div(), std::ldiv(), std::lldiv()` to be `constexpr`
.

# Changelog
libstdc++-v3/ChangeLog:

* include/c_compatibility/stdlib.h: (WIP See comment above about `using
std::div`.)
* include/c_global/cstdlib: Implements std::div() as constexpr.
* testsuite/26_numerics/headers/cstdlib/constexpr_div.cc: Tests run- and
compile-time results of std::div().

# Testcases
A test file checking the basic functionality as well as constexpr for C++23
has been added (`constexpr_div.cc`).

# Patch
(Appended to mail.)

Cheers
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20240811/39f46f5b/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-constexpr-std-div-tests.patch
Type: text/x-patch
Size: 7735 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20240811/39f46f5b/attachment.bin>


More information about the Libstdc++ mailing list