From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C71E23840019; Thu, 1 Jul 2021 20:09:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C71E23840019 From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/100976] [C++23] Make constexpr reference temp constexpr Date: Thu, 01 Jul 2021 20:09:58 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: mpolacek 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2021 20:09:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100976 --- Comment #3 from Marek Polacek --- (In reply to Jason Merrill from comment #2) > Or rather, >=20 > int main() > { > constexpr const int &r =3D 42; > static_assert(r =3D=3D 42); // { dg-bogus "" } > } >=20 > [expr.const]/4.7 says that "a temporary object of non-volatile > const-qualified literal type whose lifetime is extended to that > of a variable that is usable in constant expressions" is usable in a > constant expression. This was actually CWG 2126 which we don't seem to fully implement: struct A { int n; }; const A &a =3D {1}; // const temporary A &b =3D (A &)(const A &)A{1}; // const temporary A &&c =3D (A &&)(const A &)A{1}; // const temporary static_assert(a.n =3D=3D 1, ""); static_assert(b.n =3D=3D 1, ""); static_assert(c.n =3D=3D 1, "");=