From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DEBF4385C426; Thu, 16 Apr 2020 23:50:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEBF4385C426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587081011; bh=dETbAHADDe+q3mRVm4qx35t3fLwwJns6xKQiVHAXNXg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=F4qIwU8VsFm6SQilwUwVDTBTzFLAm5r5NsE3FWarIXX4UCWRXa2FyaXJZrWrLvQd+ dNHe/LtAwUTufxwO332kbu26YIvdwGuvHdHs+4uuOuGP6+XvrkBdKZ5j8jx7rbZf6A i09X7YTJznIx659eo3Qjd8rdxOz0NTpmsGzNkrTM= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/92326] [10 Regression] wrong bound in zero-length array diagnostics Date: Thu, 16 Apr 2020 23:50:11 +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: 10.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: trivial X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: msebor at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: resolution bug_status 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 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: Thu, 16 Apr 2020 23:50:12 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D92326 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|REOPENED |RESOLVED --- Comment #10 from Martin Sebor --- This bug isn't about whether or not a warning is issued but about the forma= t of the flexible array member printed by it: it should be 'int[]' but was 'int[= 0]'. (That's why Jeff and I have been wondering what you meant.) The warning in the test case in comment #9 is justified: the flexible array= has no elements because struct a is defined but doesn't initialize it with any (there would be no warning if the struct were only declared but not defined= ). Hopefully this test case will explain it: $ cat pr92326.c && gcc -O2 -S -Wall pr92326.c struct A a; // a.flexible has no elements int c, d; struct A { int scalar; int flexible[]; }; void g() { a.flexible[c] =3D d; // out-of-bounds regardless of c } struct A a2 =3D { 1, { 0 } }; // b.flexible has 1 element void g2 (void) { a2.flexible[c] =3D d; // out-of-bounds only if c !=3D 0 (probably shoul= d warn) } extern struct A a3; // b.flexible might have one or more elements void g3 (void) { a3.flexible[c] =3D d; // unknown if it's in-bounds or out-of-bounds } pr92326.c: In function =E2=80=98g=E2=80=99: pr92326.c:11:13: warning: array subscript is outside array bounds= of =E2=80=98int[]=E2=80=99 [-Warray-bounds] 11 | a.flexible[c] =3D d; // out-of-bounds regardless of c | ~~~~~~~~~~^~~ pr92326.c:7:7: note: while referencing =E2=80=98flexible=E2=80=99 7 | int flexible[]; | ^~~~~~~~ pr92326.c:1:10: note: defined here =E2=80=98a=E2=80=99 1 | struct A a; // a.flexible has no elements | ^=