https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92326

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|REOPENED                    |RESOLVED

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
This bug isn't about whether or not a warning is issued but about the format 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] = d;   // out-of-bounds regardless of c
}

struct A a2 = { 1, { 0 } };   // b.flexible has 1 element

void g2 (void) {
  a2.flexible[c] = d;   // out-of-bounds only if c != 0 (probably should warn)
}

extern struct A a3;  // b.flexible might have one or more elements

void g3 (void) {
  a3.flexible[c] = d;   // unknown if it's in-bounds or out-of-bounds
}

pr92326.c: In function ‘g’:
pr92326.c:11:13: warning: array subscript <unknown> is outside array bounds of
‘int[]’ [-Warray-bounds]
   11 |   a.flexible[c] = d;   // out-of-bounds regardless of c
      |   ~~~~~~~~~~^~~
pr92326.c:7:7: note: while referencing ‘flexible’
    7 |   int flexible[];
      |       ^~~~~~~~
pr92326.c:1:10: note: defined here ‘a’
    1 | struct A a;   // a.flexible has no elements
      |          ^

Reply via email to