https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66411
Bug ID: 66411 Summary: False positive in array bound check in a for loop Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dougkwan at google dot com Target Milestone: --- gcc-4.9.2 produces a bogus out of bound warning for the following test case ---- class A; class C { void m_fn1(); A *a_; }; class A { public: void m_fn2(); int elements_[8]; int num_elements_; }; int a; void A::m_fn2() { int b = 0; if (num_elements_) ++b; for (int i = b + 1; i < num_elements_; ++i) { if (elements_[i]) ++a; } } void C::m_fn1() { a_->m_fn2(); } ---- sh-4.3$ ~/gcc-4.9.2/install/bin/g++ -O3 -Werror=array-bounds bug.cc -c -o /dev/null bug.cc: In member function ‘void A::m_fn2()’: bug.cc:21:20: error: array subscript is above array bounds [-Werror=array-bounds] if (elements_[i]) ^ bug.cc: In member function ‘void C::m_fn1()’: bug.cc:21:20: error: array subscript is above array bounds [-Werror=array-bounds] if (elements_[i]) ^ cc1plus: some warnings being treated as errors sh-4.3$ gcc config: sh-4.3$ ~/gcc-4.9.2/install/bin/g++ -v Using built-in specs. COLLECT_GCC=/usr/local/google/home/dougkwan/gcc-4.9.2/install/bin/g++ COLLECT_LTO_WRAPPER=/usr/local/google/home/dougkwan/gcc-4.9.2/install/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.9.2/configure --enable-languages=c,c++ --disable-bootstrap --disable-multilib Thread model: posix gcc version 4.9.2 (GCC)