]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Use rvalues in std::string::resize_and_overwrite (LWG 3645)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 22 Mar 2023 11:54:31 +0000 (11:54 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 22 Mar 2023 17:48:20 +0000 (17:48 +0000)
commitba4f5530c475eadd2a7edb46b6c1c9d5f9267501
tree54b92cfef4f51a49eeeb4dbb505d4a3fcc56f1dc
parent7d4f4ce6a5dcefc5c97a8d05461653cbf536b745
libstdc++: Use rvalues in std::string::resize_and_overwrite (LWG 3645)

Previously the C++23 draft required that the callback arguments were
lvalues, which was overvable by the callback. LWG 3645 removes that
overspecification, so we can pass rvalues and the user can't modify
our local variables. I've used auto(p) to produce rvalues, which is only
supported since Clang 15, but I think that's OK for a C++23 feature.

While making this change I noticed that we weren't correctly enforcing
the requirement that the callback returns an integer-like type. Add
better assertions for the type and value.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.tcc (basic_string::resize_and_overwrite):
Pass rvalues to the callback, as now allowed by LWG 3645.
Enforce preconditions on the return value.
* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
Adjust.
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc