This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/79159] New: [7 regression] spurious array-bounds warning
- From: "sss at li-snyder dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 19 Jan 2017 21:33:17 +0000
- Subject: [Bug c++/79159] New: [7 regression] spurious array-bounds warning
- Auto-submitted: auto-generated
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: sss@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.