]> gcc.gnu.org Git - 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>
Mon, 18 Mar 2024 11:28:49 +0000 (11:28 +0000)
commitd063387b783f49f0d7868259424e7e548ad1e3c2
treef7e73d068957e31e4e5d2b92ef88e6ba8e5a7c90
parentfe1c4d6cce6a35c0800f26d87c411a34cb9472bb
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.

(cherry picked from commit ba4f5530c475eadd2a7edb46b6c1c9d5f9267501)
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc
This page took 0.056869 seconds and 6 git commands to generate.