From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E41A33858C00; Fri, 15 Sep 2023 05:36:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E41A33858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694756178; bh=K3BjGnkv4kfggUh0WgD5kLUVVOdIPyNJ4V3Qxo3o9oQ=; h=From:To:Subject:Date:From; b=KukKH/vn+ha02wKtiJmosebmREEKyIciZ4ei2thdoi7crWSFjvyAF1lQwdE0tPlSz dePvH9icKrqdR02O4iaLCwi/ubyOAXMfDBPzll45owALnQTTayoHfPvWA8cNHKIJMr NN+stN74WFHsRITSVF/rFkSzTY19EbbyxXHpYUaQ= From: "malekwryyy at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/111421] New: constexpr not working with array subscript Date: Fri, 15 Sep 2023 05:36:18 +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: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: malekwryyy 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 attachments.created 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111421 Bug ID: 111421 Summary: constexpr not working with array subscript Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: malekwryyy at gmail dot com Target Milestone: --- Created attachment 55903 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55903&action=3Dedit the c program that results in the error compiled with: -std=3Dc2x -Wall -Wextra When trying to subscript a constexpr array, the compiler says the expressio= n is not constant.=20 I would expect if the index is an integer literal (or a constexpr integer) = then the resulting expression should still be constant. I tried this with -std=3Dc2x and -std=3Dgnu2x // program start typedef struct S { int i; } S; constexpr int a =3D (constexpr S){.i =3D 3}.i; // works as expected constexpr int b =3D ( &(constexpr S){.i =3D 3} )->i; // works as expected constexpr int y =3D (constexpr int[]){3}[0]; // doesn't work. Compiler says expression not constant int main() { return 0; } // program end the compiler error I get is: :7:19: error: initializer element is not constant 7 | constexpr int y =3D (constexpr int[]){3}[0]; // doesn't work. Compi= ler says expression not constant | ^ :7:15: warning: 'y' defined but not used [-Wunused-const-variable= =3D] 7 | constexpr int y =3D (constexpr int[]){3}[0]; // doesn't work. Compi= ler says expression not constant | ^ :5:15: warning: 'b' defined but not used [-Wunused-const-variable= =3D] 5 | constexpr int b =3D ( &(constexpr S){.i =3D 3} )->i; // works as ex= pected | ^ :3:15: warning: 'a' defined but not used [-Wunused-const-variable= =3D] 3 | constexpr int a =3D (constexpr S){.i =3D 3}.i; // works as expected | ^ Compiler returned: 1=