From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0C50A3857032; Mon, 10 Aug 2020 16:25:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C50A3857032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597076731; bh=rMF6JiC/JwfVS5C1yPs1vsliBju1iFRZ+tKQ6e1ks20=; h=From:To:Subject:Date:From; b=xjjdaVpzcOf2TFUf1rX6WiXKyDiwLpUDuR8c6JfSIlyiFyA9CM52oXpf8OU6mvGSs MxIEu5xi5A32vPoKtA0Tr4F19CZZO2D1hIiiotwqGOMp8JDrnfE1+rWlNEMBgNohtD u8s/kNx+dRZumDRLd7HNdCkSRdZzYLMISN28VRt0= From: "barry.revzin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96557] New: Diagnostics: Can you tell me why it's not a constant expression? Date: Mon, 10 Aug 2020 16:25:30 +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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: barry.revzin 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: Mon, 10 Aug 2020 16:25:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96557 Bug ID: 96557 Summary: Diagnostics: Can you tell me why it's not a constant expression? Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Consider: struct X { char storage[100] =3D {}; char const* head =3D storage; }; void f() { constexpr X x =3D {}; } gcc correctly rejects this with: error: 'X{"", ((const char*)(& x.X::storage))}' is not a constant expression 7 | constexpr X x =3D {}; | ^ It'd be great if the error here actually indicated _why_ it's not a constant expression (or how to fix it). clang does a little bit better: :7:17: error: constexpr variable 'x' must be initialized by a const= ant expression constexpr X x =3D {}; ^ ~~ :7:17: note: pointer to subobject of 'x' is not a constant expressi= on :7:17: note: declared here But ideally we get some message about specifically 'head' pointing to 'stor= age' and a fixup suggesting making the variable x static.=