https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84050
Bug ID: 84050 Summary: missing -Warray-bounds accessing a struct array member Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC diagnoses tnhe out-of-bounds array index in function farray() below but fails to diagnose the same bug in fstatic_array. $ cat t.c && gcc -O2 -S -Wall t.c struct A { int a[3]; }; int fstatic_array (void) { static struct A a = { { 1, 2, 3 } }; return a.a[7]; // missing -Warray-bounds } int farray (void) { extern struct A f (void); struct A a = f (); return a.a[7]; // -Warray-bounds (good) } t.c: In function ‘farray’: t.c:16:13: warning: array subscript 7 is above array bounds of ‘int[3]’ [-Warray-bounds] return a.a[7]; // -Warray-bounds (good) ~~~^~~