]> gcc.gnu.org Git - gcc.git/commit
libstdc++: std::string move assignment should not use POCCA trait [PR116641]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 10 Sep 2024 13:25:41 +0000 (14:25 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 10 Sep 2024 17:22:32 +0000 (18:22 +0100)
commitc07cf418fdde0c192e370a8d76a991cc7215e9c4
treecfc6067cedb0b43f234cbdc21a9c3e17b15e7c7e
parent0008050b9d6046ba4e811a03b406fb5d98707cae
libstdc++: std::string move assignment should not use POCCA trait [PR116641]

The changes to implement LWG 2579 (r10-327-gdb33efde17932f) made
std::string::assign use the propagate_on_container_copy_assignment
(POCCA) trait, for consistency with operator=(const basic_string&).
However, this also unintentionally affected operator=(basic_string&&)
which calls assign(str) to make a deep copy when performing a move is
not possible. The fix is for the move assignment operator to call
_M_assign(str) instead of assign(str), as this just does the deep copy
and doesn't check the POCCA trait first.

The bug only affects the unlikely/useless combination of POCCA==true and
POCMA==false, but we should fix it for correctness anyway. it should
also make move assignment slightly cheaper to compile and execute,
because we skip the extra code in assign(const basic_string&).

libstdc++-v3/ChangeLog:

PR libstdc++/116641
* include/bits/basic_string.h (operator=(basic_string&&)): Call
_M_assign instead of assign.
* testsuite/21_strings/basic_string/allocator/116641.cc: New
test.
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/testsuite/21_strings/basic_string/allocator/116641.cc [new file with mode: 0644]
This page took 0.055389 seconds and 5 git commands to generate.