https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105319
Bug ID: 105319 Summary: Unexpected warning with zero-length sized array using -std=gnu99 and -O2 Product: gcc Version: 10.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: piannetta at kalrayinc dot com Target Milestone: --- // main.c #define LEN 0 static volatile int tab[LEN]; int main (int argc, char * argv[]) { tab[argc] = 0; } The code above builds fine with: gcc -Wall -std=gnu99 but reports a warning when compiled with -O2: gcc -Wall -std=gnu99 -O2 main.c: In function ‘main’: main.c:4:12: warning: array subscript argc is outside array bounds of ‘volatile int[0]’ [-Warray-bounds] 4 | tab[argc] = 0; | ~~~^~~~~~ main.c:2:21: note: while referencing ‘tab’ 2 | static volatile int tab[LEN]; | ^~~ I've observed this behavior on gcc 10.3.1 and on gcc 12.0.1 (I have not tested other versions). I would have expected that the snippet would compile the same way in both cases and not produce a warning since gnu99 supports zero-length arrays.