Also while adding a test for the fix for bug 88956 I noticed that GCC doesn't diagnose indexing into zero-length arrays. The out-of-bounds accesses to the global zero-length arrays are folded to zero while those to the local ones are emitted. $ gcc -O2 -S -Wall t.c const char s1[1] = { }; int f1 (void) { return s1[3]; // -Warray-bounds (good) } const char s0[0] = { }; int f0 (void) { return s0[3]; // missing warning } int g1 (void) { const char s1[1] = { }; return s1[3]; // -Warray-bounds (good) } int g0 (void) { const char s0[0] = { }; return s0[3]; // missing warning } t.c: In function ‘f1’: t.c:4:12: warning: array subscript 3 is above array bounds of ‘const char[1]’ [-Warray-bounds] 4 | return s1[3]; // -Warray-bounds (good) | ~~^~~ t.c:1:12: note: while referencing ‘s1’ 1 | const char s1[1] = { }; | ^~ t.c: In function ‘g1’: t.c:17:12: warning: array subscript 3 is above array bounds of ‘const char[1]’ [-Warray-bounds] 17 | return s1[3]; // -Warray-bounds (good) | ~~^~~ t.c:16:14: note: while referencing ‘s1’ 16 | const char s1[1] = { }; | ^~
Fixed in GCC 10.