]> 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>
Thu, 18 Nov 2021 16:14:15 +0000 (16:14 +0000)
commitca243ada71656651a8753e88164a1f0f019be1c3
tree1818ddadb761c14d7987a57b6fffae8fbb9655cb
parent16fab6d691b1410abdf794230246ab9753d183af
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.
libstdc++-v3/include/bits/char_traits.h
libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc