]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Use constexpr-if for std::basic_string::_S_copy_chars
authorJonathan Wakely <jwakely@redhat.com>
Thu, 10 Apr 2025 11:21:26 +0000 (12:21 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 11 Apr 2025 12:17:15 +0000 (13:17 +0100)
commit648d5c26e25497249e1d381449f2bf66418b997c
treedd6cd8821fd8a0e21ec7a8c29ac5c02e6cbd42b7
parentae54d8cb51eb5cc1f5a3d319cc1840d2e9bfcbfc
libstdc++: Use constexpr-if for std::basic_string::_S_copy_chars

For C++11 and later we can remove four overloads of _S_copy_chars and
use constexpr-if in the generic _S_copy_chars. This simplifies overload
resolution for _S_copy_chars, and also means that we use the optimized
memcpy path for other iterators such as std::vector<char>::iterator.

We still need all the _S_copy_chars overloads to be part of the explicit
instantiation definition, so make them depend on the macro that is
defined by src/c++11/string-inst.cc for that purpose.

For C++98 the _S_copy_chars  overloads are still needed, but the macros
_GLIBCXX_NOEXCEPT and _GLIBCXX20_CONSTEXPR do nothing for C++98, so this
change removes them from those overloads.  When instantiated in
src/c++11/string-inst.cc the removed _GLIBCXX_NOEXCEPT macros would
expand to 'noexcept', but in practice that doesn't make any difference
for those instantiations. At -O2 the instantiations inline all the calls
to _S_copy_chars and the presence or absence of noexcept doesn't change
anything in the generated code.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (_S_copy_chars): Replace overloads
with constexpr-if and extend optimization to all contiguous
iterators.
* src/c++11/string-inst.cc: Extend comment.

Reviewed-by: Tomasz Kaminski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/src/c++11/string-inst.cc