From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD1FF385559E; Tue, 7 Mar 2023 16:24:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD1FF385559E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678206279; bh=ei/tSzjrFJn5buOckriUkOtK8X/JB2eO+u7ZVaOg1bY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Y0JYzDUsd7CC91LartgxKJnuZ2oDbj+tUiA83+6d+t7f0xlSuDlelDkAnGrARqY7s bl5BzWP2UabH2jVhZ4C34SPr0xt35ZUH1+BeECwLR0xlxsF6y4Op/Le8+iy0nlB6mh i4/tgVLfvBfJ0jacMxk3fgt08DVMZYfwEo2S06OA= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107079] [10/11/12 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer Date: Tue, 07 Mar 2023 16:24:39 +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: 13.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 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=3D107079 --- Comment #8 from CVS Commits --- The releases/gcc-12 branch has been updated by Marek Polacek : https://gcc.gnu.org/g:fb82334341e21ad0254f63e942be276f62d111cf commit r12-9233-gfb82334341e21ad0254f63e942be276f62d111cf Author: Marek Polacek Date: Wed Feb 8 14:02:48 2023 -0500 c++: ICE initing lifetime-extended constexpr var [PR107079] We ICE on the simple: struct X { const X* x =3D this; }; constexpr const X& x =3D X{}; where store_init_value initializes 'x' with &TARGET_EXPR }> but we must lifetime-extend via extend_ref_init_temps and we get _ZGR1x_.x =3D (const struct X *) & >>>;, (= const struct X &) &_ZGR1x_; Since 'x' was declared constexpr, we do cxx_constant_init and we hit the preeval code added in r269003 while evaluating the INIT_EXPR: _ZGR1x_.x =3D (const struct X *) & >>> but we have no ctx.ctor or ctx.object here so lookup_placeholder won't find anything that could replace X and we ICE on 7861 /* A placeholder without a referent. We can get here when 7862 checking whether NSDMIs are noexcept, or in massage_init_elt; 7863 just say it's non-constant for now. */ 7864 gcc_assert (ctx->quiet); because cxx_constant_init means !ctx->quiet. It's not correct that there isn't a referent. I think the following patch is a pretty straightforward fix: pass the _ZGR var down to maybe_constant_init so that it can replace the PLACEHOLDER_EXPR with _ZGR1x_. The commented assert in the test doesn't pass: we complain that _ZGR1x_ isn't a constexpr variable because we don't implement DR2126 (PR101588). PR c++/107079 gcc/cp/ChangeLog: * call.cc (set_up_extended_ref_temp): Pass var to maybe_constant_init. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-nsdmi2.C: New test. (cherry picked from commit 67b82bc1b29b82e4577df9491793624f3a8eb12f)=