https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101600
Bug ID: 101600 Summary: Spurious -Warray-bounds Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sbergman at redhat dot com Target Milestone: --- With recent GCC 12 trunk (but not with e.g. gcc-c++-11.1.1-3.fc34.x86_64): > $ cat test.cc > struct S1 { virtual ~S1(); }; > struct S2 { int m; }; > struct S3 { virtual ~S3(); }; > struct S4: S1, S2, S3 {}; > int f1(); > void f2(S3 *); > void f3(S2 * p) { > for (int i = f1(); f1();) { > if (i == 0) { > p = nullptr; > break; > } > } > f2(static_cast<S4 *>(p)); > } > $ g++ -c -O2 -Warray-bounds -O2 test.cc > test.cc: In function ‘void f3(S2*)’: > test.cc:14:7: warning: array subscript 0 is outside array bounds of ‘S2 > [2305843009213693951]’ [-Warray-bounds] > 14 | f2(static_cast<S4 *>(p)); > | ~~^~~~~~~~~~~~~~~~~~~~~~ > test.cc:7:14: note: at offset -8 into object ‘p’ of size [0, > 9223372036854775807] > 7 | void f3(S2 * p) { > | ~~~~~^