From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 75E3E3841908; Mon, 13 Nov 2023 10:11:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75E3E3841908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699870276; bh=zqxxYrOxYNGoFbQdq87ZC7zDZWK950LhfhCWRDUkFE8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tNijVFZMSAkNOOdpL6h2ngaPlac/+QoUOtfxApzMMOwZyIUN4bFUxeQ+XRSP5Zr77 7FgbHkgPWzecWsHRNusUDK7RMwmxv7z3j7xHxKLiK3jeE8Iks61W79ysSC0xBmC7jL ms6Gi+hG1ymfwOj27t6xsmQAFnTW36fDeQY8jTZ0= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112480] optional::reset emits inefficient code when T is trivially-destructible Date: Mon, 13 Nov 2023 10:11:16 +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: 13.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi 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=3D112480 --- Comment #6 from Jonathan Wakely --- I think I prefer: --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -311,6 +311,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (this->_M_engaged) _M_destroy(); + + // The following seems redundant but improves codegen, see PR 11248= 0. + if constexpr (is_trivially_destructible_v<_Tp>) + this->_M_engaged =3D false; } };=