From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8046C3861859; Thu, 16 Nov 2023 22:36:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8046C3861859 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700174194; bh=REQDSqUnBxIpQpX74+LAjc6DQJlOrU8Nv+adYSvPLr4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mKZUUBIQ7UCA9fFqIJTM83Nk6zX+NfQHJb0ZDQEorVemEVRpOkZE59aaYVUw0hZRd Td3vp7Zy4xAvTRU9SmzJQFICu+qenBEUmJB6siTkelnUEc2f1qsCDWQZ5WO/ABHOur SU6KGly124yAHIXcYoz9zwjgXilvZrRMl6yIfP84= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106650] [C++23] P2280 - Using unknown references in constant expressions Date: Thu, 16 Nov 2023 22:36:17 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek 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=3D106650 --- Comment #2 from Marek Polacek --- With just --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -7378,6 +7378,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ct= x, tree t, r =3D build_constructor (TREE_TYPE (t), NULL); TREE_CONSTANT (r) =3D true; } + else if (TYPE_REF_P (TREE_TYPE (t))) + /* P2280 */; else { if (!ctx->quiet) the test from P2280 behaves as expected: $ xg++ -c z.C -std=3Dc++20 z.C: In function =E2=80=98void splash(Swim&)=E2=80=99: z.C:35:33: error: non-constant condition for static assertion 35 | static_assert(pswam->phelps() =3D=3D 28); // error: lvalue-to-rvalue conversion on a pointer | ~~~~~~~~~~~~~~~~^~~~~ z.C:35:17: error: the value of =E2=80=98pswam=E2=80=99 is not usable in a c= onstant expression 35 | static_assert(pswam->phelps() =3D=3D 28); // error: lvalue-to-rvalue conversion on a pointer | ^~~~~ z.C:34:9: note: =E2=80=98pswam=E2=80=99 was not declared =E2=80=98constexpr= =E2=80=99 34 | Swim* pswam =3D &swam; | ^~~~~ z.C:41:31: error: non-constant condition for static assertion 41 | static_assert(swam.lochte() =3D=3D 12); // error: invok= ing virtual function on reference | ~~~~~~~~~~~~~~^~~~~ z.C:41:28: error: =E2=80=98* & swam=E2=80=99 is not a constant expression 41 | static_assert(swam.lochte() =3D=3D 12); // error: invok= ing virtual function on reference | ~~~~~~~~~~~^~ z.C:44:31: error: non-constant condition for static assertion 44 | static_assert(swam.coughlin =3D=3D 12); // error: lvalue-to-rvalue conversion on an object | ~~~~~~~~~~~~~~^~~~~ z.C:44:31: error: =E2=80=98swam=E2=80=99 is not a constant expression z.C: At global scope: z.C:52:36: error: the value of =E2=80=98trident=E2=80=99 is not usable in a= constant expression 52 | constexpr auto& gallagher =3D typeid(trident); // error: constexpr-unknown dynamic type | ^~~~~~~ z.C:49:14: note: =E2=80=98trident=E2=80=99 was not initialized with a const= ant expression 49 | extern Swim& trident; | ^~~~~~~ It cannot be that easy, can it?=