https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79159
Bug ID: 79159 Summary: [7 regression] spurious array-bounds warning Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: s...@li-snyder.org Target Milestone: --- hi - gcc version 7.0.0 20170119 gives what appears to be a spurious warning for this example when compiling with -O3 (tested on x86_64-pc-linux-gnu): ================================================================ void foo(float tmpCorr[9][9]); float bar; void finalDigits(int& n) { float tmpCorr[9][9] = {{0}}; foo(tmpCorr); for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { bar = tmpCorr[i][j]; } } } ================================================================ $ ~/gcc/build/gcc/cc1plus -quiet -O3 -Wall x.cc x.cc: In function ‘void finalDigits(int&)’: x.cc:11:25: warning: array subscript is above array bounds [-Warray-bounds] bar = tmpCorr[i][j]; ~~~~~~~~~~~~^ I do not see this warning with gcc 6.3.1. This doesn't make sense, since there is no basis for making any assumptions about the value of the iteration limit n. The warning goes away if i remove the call to foo(), if function parameter is changed to be passed by value rather than by reference, or if the lower limit of the j iteration is changed to i rather than i+1.