[committed 2/2] libstdc++: Simplify constexpr checks in std::char_traits [PR 91488]

Jonathan Wakely jwakely@redhat.com
Fri Jun 18 10:25:51 GMT 2021


On 17/06/21 22:45 +0100, Jonathan Wakely wrote:
>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.

The attached patch is the backport. Instead of removing the
__constant_string_p and __constant_array_p functions entirely, just
give them external linkage. That seems to avoid the bug, and means the
release branches can still be used with older non-GCC compilers which
don't support __builtin_is_constant_evaluated yet.

Tested x86_64-linux. Committed to gcc-11 for now, gcc-10 and gcc-9 to
follow soon.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 5365 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210618/c0f2c7c7/attachment.bin>


More information about the Gcc-patches mailing list