From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 469363858CD1; Thu, 2 Nov 2023 07:30:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 469363858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698910258; bh=mComSloKI8OPpoJmPiO0e3CBPblAhlV3ACXNnRNAXHQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U2pcBlukrPHDAsNuNPdAt1e8ojP9YNbxyaM20l50tW+LANGmHEqSXILca46hexZ8F F1AqR10bStVTziiyPFQv0D+5q9mRk/ekQwCMjJkKcyUo0jtBB6Zgld7wjbr8EazFPx EtA1fj7gOs0chbNS7beV8L9jOMgEZ5bNPR4Et+KY= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112335] missed optimization on reset and assign unique_ptr Date: Thu, 02 Nov 2023 07:30:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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=3D112335 --- Comment #4 from Andrew Pinski --- (In reply to Federico Kircheis from comment #2) > > Well s::~s could touch the reference std::unique_ptr (ps1). >=20 > In both cases, s::~s is called only once. >=20 > Also during the move-assignment no user-provided-code is involved (except > the destruction of ps1, and even case of a user-provided deleter, it is o= nly > called if the pointer is not nullptr. NO. NO. std::unique_ptr t; __thread bool tt; inline s::~s() { if (tt) return; tt =3D true; t.reset(new s); tt =3D false; } Is still a valid ~s as far as I can tell. Yes it is odd but so what it is still valid. Now will anyone write code like this, doubt it. Also note clang does not optimize this with either libstdc++ or libc++.=