From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 49A83387088B; Tue, 16 May 2023 12:50:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49A83387088B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684241407; bh=bmJs3hgKIzduoL6pYyNxV8YJ7/M+bIsypvfGdKQemcI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RgDJ9V5lrmfrpfy41gL/VrZBnHhd+89uxdXSxbJv9SbmG/pkmdTs2l1z4nKVDHdd4 5aaw+wyHl87jjIKti3ZN1O82NoMAkh2OTe/V1gmE/sd9xcgz+PnIwMH1qieavBJHGN 9yWOPMlnj3s7HMOhvl8kW/ZP512lZZ5fHOUXGTjI= 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: Tue, 16 May 2023 12:50:06 +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: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.4 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 #8 from CVS Commits --- The releases/gcc-11 branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:9578570e305e77b8c105583506781158c137f743 commit r11-10768-g9578570e305e77b8c105583506781158c137f743 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. (cherry picked from commit 92eb0adc14a5f84acce7e5bc780b81b1544b24aa)=