From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4B4BC3831BE6; Fri, 16 Dec 2022 14:30:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B4BC3831BE6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671201050; bh=fcAWxx9H0TFriNzdBrXVnatvoH0HZm3fx5OqObMJxT0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=buRGvCITKfKMnV2wd41yV4n1ZN9NzVZWSr4jUQv4TmqoanZwEQ1J9iUsaiqjuAaJi uleF1wvAPxbETv1b5S83gyQNO5gYrBVWcNp8LWocXAsuHD0HvM6D46QQVH0OjTZWFm qC47fbiPtEwxYt8zSZG5pNhwnWXBSmHtJiNuIUDo= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108118] std::weak_ptr lacks a self-usurp check on move Date: Fri, 16 Dec 2022 14:30:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108118 --- Comment #6 from CVS Commits --- The master branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:92eb0adc14a5f84acce7e5bc780b81b1544b24aa commit r13-4745-g92eb0adc14a5f84acce7e5bc780b81b1544b24aa Author: Jonathan Wakely 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 =3D std::exchange(rhs._M_ptr, nullptr); _M_refcount =3D 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=3D): Implement as move-and-swap exactly as specified in the standard. * testsuite/20_util/weak_ptr/cons/self_move.cc: New test.=