http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59564
Bug ID: 59564 Summary: False positive array -Warray-bounds check with -O2 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: egor_suvorov at mail dot ru Created attachment 31482 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31482&action=edit Output of gcc with '-v -save-temps' Here's a full code: int arr[1]; int n = 0; int main() { if (n <= 0) n = 0; arr[n] = 0; if (n <= 0) n = 0; return 0; } If you compile this code with '-O2 -Warray-bounds', gcc produces warning, which is obviously incorrect. You can also change inequality checks to >= and you'll get another similar warning. I've checked it on mingw 4.8.1, mingw 4.7.2 and on debian gcc 4.7.2 - works everywhere. You can also save this file as .cpp and compile with g++ - bug persists.