libstdc++: Simplify constexpr checks in std::char_traits [PR 91488]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 17 Jun 2021 13:11:22 +0000 (14:11 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 17 Jun 2021 21:00:58 +0000 (22:00 +0100)
commitb376b1ef38971b84975ad1540bf5d2ae0b924e76
treee81a073a91795524bc4a7241d9ac7987d82861e6
parent331e20a69be0d9e7d448580945945d4c7a1e3c0a
libstdc++: Simplify constexpr checks in std::char_traits [PR 91488]

This removes the helper functions added by r8-1294 to detect whether the
char_traits member functions can be evaluated at compile time. Instead,
we can just use __builtin_constant_evaluated directly, which is well
supported by non-GCC compilers by now.

As a result, there is a chance that those members will no longer be
usable in constant expressions when using old versions of non-GCC
compilers. Make the relevant feature test macros depend on the
availability of __builtin_constant_evaluated, so they are defined only
when the feature is actualyl available.

The new testcase from the PR is added to the libitm testsuite, because
that's where we can be sure it's OK to use the -fgnu-tm option.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/91488

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (__cpp_lib_constexpr_string): Only
define when is_constant_evaluated is available.
* include/bits/char_traits.h (__cpp_lib_constexpr_char_traits):
Likewise.
(__constant_string_p, __constant_array_p): Remove.
(char_traits): Use is_constant_evaluated directly.
* include/std/version (__cpp_lib_constexpr_char_traits)
(__cpp_lib_constexpr_string): Only define when
is_constant_evaluated is available.

libitm/ChangeLog:

* testsuite/libitm.c++/libstdc++-pr91488.C: New test.
libitm/testsuite/libitm.c++/libstdc++-pr91488.C [new file with mode: 0644]
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/char_traits.h
libstdc++-v3/include/std/version