[Bug libstdc++/108118] std::weak_ptr lacks a self-usurp check on move
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Mar 28 23:35:42 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108118
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:629ed996f32cb03dd712789eede1f7f2036e497b
commit r12-9351-g629ed996f32cb03dd712789eede1f7f2036e497b
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Dec 15 09:52:48 2022 +0000
libstdc++: Fix self-move for std::weak_ptr [PR108118]
I think an alternative fix would be something like:
_M_ptr = std::exchange(rhs._M_ptr, nullptr);
_M_refcount = std::move(rhs._M_refcount);
The standard's move-and-swap implementation generates smaller code at
all levels except -O0 and -Og, so it seems simplest to just do what the
standard says.
libstdc++-v3/ChangeLog:
PR libstdc++/108118
* include/bits/shared_ptr_base.h (weak_ptr::operator=):
Implement as move-and-swap exactly as specified in the standard.
* testsuite/20_util/weak_ptr/cons/self_move.cc: New test.
(cherry picked from commit 92eb0adc14a5f84acce7e5bc780b81b1544b24aa)
More information about the Gcc-bugs
mailing list