https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104603
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- -DA just changes inlining. This is just an inlining mess which you can see from the diagnostic on the trunk: In member function 'bool Base::isX() const', inlined from 'bool Base::operator==(const Base&) const' at <source>:16:15, inlined from 'bool X::operator==(const X&) const' at <source>:10:51, inlined from 'bool Base::operator==(const Base&) const' at <source>:16:63, inlined from 'bool X::operator==(const X&) const' at <source>:10:51, inlined from 'void f()' at <source>:24:11: <source>:4:29: warning: array subscript 2 is outside array bounds of 'X [1]' [-Warray-bounds] 4 | bool isX() const { return isX_; } | ^~~~ The warning happens before some other optimizations happen which allows GCC to prove the function will just always return false ...