From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1D6483858423; Sun, 16 Apr 2023 09:31:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D6483858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681637469; bh=jxxbBcVEpcXkhUJwCo66CYmPJlui+JBAlb785sOcH0Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=djr7IC2ugQnCqXy9wCHxG3MiOFe6KWXj5Jmxuna1a4U8N0cappqdpXTpRfTZYaG+z u6o4nD5iU3vYbeqHlxsAlu2WgMthWyxJb2izHHYwdnSzGgfQzNpb0nCzuzVvq9gudI eSRFz/ciHrLWVGEj2OkvTFfV37wAXmCrbyxuf8NY= From: "federico at kircheis dot it" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101557] the value of '' is not usable in a constant expression Date: Sun, 16 Apr 2023 09:31:07 +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: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: federico at kircheis dot it 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: 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=3D101557 --- Comment #5 from Federico Kircheis --- Today I just found a possible workaround that involves macros and lambdas... ---- struct node { const char* d; const node& left; }; #define LEAF(a) []()-> const node&{ constexpr static auto a =3D node{"a",Nu= ll}; return a; }() #define NODE(a,b) []()-> const node&{constexpr static auto a =3D node{"a",b= }; return a; }() constexpr node Null =3D node{"",Null}; constexpr auto a =3D node{"a",NODE(a,LEAF(b))}; constexpr auto a2 =3D node{"a",node{"a", node{"a", Null}}}; constexpr int mysize(const node& n) noexcept{ return (&n =3D=3D &Null) ? 0 : 1 + mysize(n.left);=20 } constexpr auto size0 =3D mysize(Null); static_assert(size0 =3D=3D 0, ""); constexpr auto size3 =3D mysize(a); static_assert(size3 =3D=3D 3, ""); ---- "mysize(a)" compiles, while "mysize(a2)" does not, even if the two datastructures are equivalent Unfortunately clang does not accept it=