As reported in https://bugzilla.redhat.com/show_bug.cgi?id=1907216, GCC 11 issues a spurious -Warray-bounds on the following code (reduced from the original test case): $ cat rhbz1738791.C && g++ -O2 -S -Wall rhbz1738791.C struct A { virtual ~A() noexcept; const char* s; }; struct B: virtual A { }; struct C: virtual B { }; struct D: virtual A { }; struct E: virtual B, virtual D { E (const char*); }; void f (E); void g_function () { f (E ("")); } rhbz1738791.C: In function ‘void g_function()’: rhbz1738791.C:11:8: warning: array subscript ‘D[1]’ is partly outside array bounds of ‘E [1]’ [-Warray-bounds] 11 | struct D: virtual A { }; | ^ rhbz1738791.C:22:11: note: while referencing ‘<anonymous>’ 22 | f (E ("")); | ^ rhbz1738791.C:11:8: warning: array subscript ‘D[1]’ is partly outside array bounds of ‘E [1]’ [-Warray-bounds] 11 | struct D: virtual A { }; | ^ rhbz1738791.C:22:11: note: while referencing ‘<anonymous>’ 22 | f (E ("")); | ^
The problem is most likely the same as in pr97595 (except in gimple-array-bounds.cc).
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-January/563894.html
See pr22488 for the underlying problem with the difference between DECL_SIZE and TYPE_SIZE of classes with virtual bases.
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>: https://gcc.gnu.org/g:f3daa6c0fd8d79ae45eac2dd0f274da1aa71c958 commit r11-7563-gf3daa6c0fd8d79ae45eac2dd0f274da1aa71c958 Author: Martin Sebor <msebor@redhat.com> Date: Mon Mar 8 13:37:21 2021 -0700 PR middle-end/98266 - bogus array subscript is partly outside array bounds on virtual inheritance gcc/ChangeLog: PR middle-end/98266 * gimple-array-bounds.cc (inbounds_vbase_memaccess_p): New function. (array_bounds_checker::check_array_bounds): Call it. gcc/testsuite/ChangeLog: PR middle-end/98266 * g++.dg/warn/Warray-bounds-15.C: New test. * g++.dg/warn/Warray-bounds-18.C: New test. * g++.dg/warn/Warray-bounds-19.C: New test. * g++.dg/warn/Warray-bounds-20.C: New test. * g++.dg/warn/Warray-bounds-21.C: New test.
Fixed in r11-7563.