Please see 43949 which was about a very similar test case. $ cat test.cpp void f();
int c[3]; int result; struct Vector { static int get(int i) { if (i >= 3) f(); return c[i]; } }; void g(int index) { result = Vector::get(index) + Vector::get(index); } $ g++ -Wall -c test.cpp [no warnings] $ g++ -Wall -c -O2 test.cpp test.cpp: In function void g(): test.cpp:10:19: error: array subscript is above array bounds $ g++ -v Using built-in specs. COLLECT_GCC=/prefix/gcc-4.5.0/x86_64-unknown-linux-gnu/bin/g++ COLLECT_LTO_WRAPPER=/prefix/gcc-4.5.0/x86_64-unknown-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/prefix/gcc-4.5.0 --exec-prefix=/prefix/gcc-4.5.0/x86_64-unknown-linux-gnu --enable-version-specific-runtime-libs --enable-stage1-checking --disable-nls --with-system-zlib --enable-multilib --enable-languages=c,c++,objc --with-gmp-include=/prefix/gmp-4.2.2/x86_64-unknown-linux-gnu/include --with-gmp-lib=/prefix/gmp-4.2.2/x86_64-unknown-linux-gnu/lib --with-mpfr-include=/prefix/mpfr-2.4.2/include --with-mpfr-lib=/prefix/mpfr-2.4.2/x86_64-unknown-linux-gnu/lib --with-mpc-include=/prefix/mpc-0.8.1/include --with-mpc-lib=/prefix/mpc-0.8.1/x86_64-unknown-linux-gnu/lib --with-gnu-as --with-as=/prefix/binutils-2.20.1/x86_64-unknown-linux-gnu/bin/as --with-gnu-ld --with-ld=/prefix/binutils-2.20.1/x86_64-unknown-linux-gnu/bin/ld Thread model: posix gcc version 4.5.0 (GCC) The bogus warning disappears if - Vector::get(index) is assigned to result (no addition) - get() is a global function The bogus warning does not appear in gcc 4.2.4 (Debian 4.2.4-6). It appears also in 4.3.2 (Debian 4.3.2-1.1), 4.4.4 (Debian 4.4.4-7) and 4.5.0 (GCC). Note that in contrast to PR43949 in this case the array subscript *could* be above array bounds depending on how g() is called, but in the code snippet itself there is no such call. -- Summary: bogus warning: array subscript is above array bounds Product: gcc Version: 4.5.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: joachim dot reichel at gmx dot de GCC build triplet: x86_64-linux-gnu GCC host triplet: x86_64-linux-gnu GCC target triplet: x86_64-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45180