From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BEE333858003; Wed, 21 Jul 2021 15:13:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEE333858003 From: "federico.kircheis at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101557] New: the value of '' is not usable in a constant expression Date: Wed, 21 Jul 2021 15:13:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: federico.kircheis at gmail dot com 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Wed, 21 Jul 2021 15:13:19 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101557 Bug ID: 101557 Summary: the value of '' is not usable in a constant expression Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: federico.kircheis at gmail dot com Target Milestone: --- Consider following snippet ---- struct node { const char* d; const node& left; const node& right; }; constexpr const node Null =3D node{"",Null,Null}; constexpr const node a=20 { "a", node { "b", node{"e",Null,Null}, node{"d",Null,Null}, }, node{"c",Null,Null}, }; constexpr int mysize(const node& n) noexcept{ return (&n =3D=3D &Null) ? 0 : 1 + mysize(n.left) + mysize(n.right);=20 } constexpr auto size0 =3D mysize(Null); static_assert(size0 =3D=3D 0, ""); constexpr auto size1 =3D mysize(node{"c", Null, Null}); static_assert(size1 =3D=3D 1, ""); constexpr auto size2 =3D mysize(node { "b", node{"e",Null,Null}, node{"d",Null,Null}, }); static_assert(size2 =3D=3D 3, ""); // this line does not compile constexpr auto size3 =3D mysize(a); static_assert(size3 =3D=3D 5, ""); ---- The expression `constexpr auto size3 =3D mysize(a);` does not compile with = the error message ---- :41:30: in 'constexpr' expansion of 'mysize(a)' :25:42: in 'constexpr' expansion of 'mysize((* & n.node::left))' :41:32: error: the value of '' is not usable in a consta= nt expression 41 | constexpr auto size3 =3D mysize(a); | ^ :22:1: note: '' was not declared 'constexpr' 22 | }; | ^ Compiler returned: 1 ---- A similar effect can be achieved with ---- constexpr node b =3D a.left; ---- with following error ---- :45:23: error: the value of '' is not usable in a consta= nt expression 45 | constexpr node b2 =3D a.left; | ^~~~ :22:1: note: '' was not declared 'constexpr' 22 | }; | ^ Compiler returned: 1 ---- even if ---- constexpr node b =3D a; ---- compiles without warnings. Generally accessing subobjects should not be an issue, for example ---- struct sub{}; struct node2{ const sub& s; }; constexpr const node2 n2{ sub{} }; constexpr auto s =3D n2.s; ---- also compiles without issues=