https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114029
Bug ID: 114029 Summary: -Warray-bounds does not warn for global arrays Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: dangelog at gmail dot com Target Milestone: --- Testcase https://gcc.godbolt.org/z/n3zPPE7bq const int test[]={1, 2, 3}; int main() { return test[3]; } GCC doesn't warn under -O2 -Wall. It does emit a -Warray-bounds warning if the `test` array is moved inside `main`; but why not warning for a global variable? For comparison, Clang always warns (even without any optimization/warning flag).