https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122197
scott snyder <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #9 from scott snyder <[email protected]> --- hi - Here's another, perhaps simpler, example that shows a -Warray-bounds warning with -O2 -Wall. I bisected this to the same commit mentioned above, and the warning goes away with --param max-devirt-targets=2 (or 1), so i guess that the underlying issue is the same is discussed here. >From a user's point of view, this kind of warning is particularly confusing. Note for example that the presence of the derived class GeoVSurface is needed to trigger this, but that's not mentioned anywhere in the warning. -------------------------------------------------------------- struct RCBase { void ref(); void unref () { if (m_count == 0) { delete this; } else if (--m_count == 0) { delete this; } } virtual ~RCBase() = default; unsigned m_count; }; struct GeoIntrusivePtr{ GeoIntrusivePtr(RCBase* obj):m_ptr{obj} { if (m_ptr) obj->ref(); } ~GeoIntrusivePtr() { if (m_ptr) m_ptr->unref(); } RCBase* m_ptr; }; void buildShape() { GeoIntrusivePtr shape { new RCBase() }; } struct GeoPlacement: public RCBase { virtual ~GeoPlacement() = default; long x; }; struct GeoVSurface : public GeoPlacement { GeoVSurface(RCBase *SurfShape) : m_surfaceshape{SurfShape} {} GeoIntrusivePtr m_surfaceshape; }; -------------------------------------------------------------- g++ (GCC) 16.0.0 20251211 (experimental) $ g++ -c -Wall -O2 x.cc In destructor ‘virtual constexpr GeoPlacement::~GeoPlacement()’, inlined from ‘virtual constexpr GeoPlacement::~GeoPlacement()’ at x.cc:41:11, inlined from ‘void RCBase::unref()’ at x.cc:9:14, inlined from ‘void RCBase::unref()’ at x.cc:4:8, inlined from ‘GeoIntrusivePtr::~GeoIntrusivePtr()’ at x.cc:26:28, inlined from ‘void buildShape()’ at x.cc:36:1: x.cc:41:11: warning: array subscript ‘GeoPlacement[0]’ is partly outside array bounds of ‘unsigned char [16]’ [-Warray-bounds=] 41 | virtual ~GeoPlacement() = default; | ^ x.cc: In function ‘void buildShape()’: x.cc:35:38: note: object of size 16 allocated by ‘operator new’ 35 | GeoIntrusivePtr shape { new RCBase() }; | ^ In destructor ‘virtual constexpr GeoPlacement::~GeoPlacement()’, inlined from ‘virtual constexpr GeoPlacement::~GeoPlacement()’ at x.cc:41:11, inlined from ‘void RCBase::unref()’ at x.cc:7:14, inlined from ‘GeoIntrusivePtr::~GeoIntrusivePtr()’ at x.cc:26:28, inlined from ‘void buildShape()’ at x.cc:36:1: x.cc:41:11: warning: array subscript ‘GeoPlacement[0]’ is partly outside array bounds of ‘unsigned char [16]’ [-Warray-bounds=] 41 | virtual ~GeoPlacement() = default; | ^ x.cc: In function ‘void buildShape()’: x.cc:35:38: note: object of size 16 allocated by ‘operator new’ 35 | GeoIntrusivePtr shape { new RCBase() }; | ^
