]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix std::char_traits<C>::move for constexpr
authorJonathan Wakely <jwakely@redhat.com>
Thu, 18 Nov 2021 12:39:20 +0000 (12:39 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 5 Jan 2022 18:20:30 +0000 (18:20 +0000)
commit0d566335a31722f8044852d9a24f492830ae5789
tree970677ec490dcffaaa3dd3c525006e4003d3cc99
parent88518e5ae0c7b4ed87ffa4ba39c1ff93c7d146dd
libstdc++: Fix std::char_traits<C>::move for constexpr

The constexpr branch in __gnu_cxx::char_traits::move compares the string
arguments to see if they overlap, but relational comparisons between
unrelated pointers are not core constant expressions.

I want to replace the comparisons with a loop using pointer equality to
determine whether the end of the source string is in the destination
string. However, that doesn't work with GCC, due to PR c++/89074 so
allocate a temporary buffer instead and copy out into that first, so
that overlapping source and destination don't matter. The allocation
isn't supported by the current Intel icc so use the loop as a fallback.

libstdc++-v3/ChangeLog:

* include/bits/char_traits.h (__gnu_cxx::char_traits::move):
Do not compare unrelated pointers during constant evaluation.
* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc:
Improve tests for char_traits::move.

(cherry picked from commit ca243ada71656651a8753e88164a1f0f019be1c3)
libstdc++-v3/include/bits/char_traits.h
libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc