https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80907
Bug ID: 80907 Summary: False positive: "warning: array subscript is above array bounds" Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cas43 at cs dot stanford.edu Target Milestone: --- THIS PROGRAM: int x[3]; int n=2; void foo() { for(int i=0;i<n;i++) for(int j=0;j<=i;j++) x[i+j]++; } PRODUCES THIS DIAGNOSTIC: prog.cpp: In function ‘void foo()’: prog.cpp:5:53: warning: array subscript is above array bounds [-Warray-bounds] for(int i=0;i<n;i++) for(int j=0;j<=i;j++) x[i+j]++; ~~~~~^ prog.cpp:5:53: warning: array subscript is above array bounds [-Warray-bounds] WHEN COMPILED LIKE THIS: g++ -c -O3 -Warray-bounds prog.cpp COMPILER VERSION: Using built-in specs. COLLECT_GCC=/home/craig/new-gcc/i-trunk/bin/g++ COLLECT_LTO_WRAPPER=/home/craig/new-gcc/i-trunk/libexec/gcc/x86_64-pc-linux-gnu/8.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../s-trunk/configure --disable-linux-futex --prefix=/home/craig/new-gcc/i-trunk --disable-multilib Thread model: posix gcc version 8.0.0 20170526 (experimental) (GCC) OTHER NOTES: In the original code, there are also assertions guarding the access: T& operator()(int i,int j) {assert((unsigned)i<2 && (unsigned)j<2);return array[i+j];}