https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120345
Bug ID: 120345
Summary: array subscript is partly outside array bounds
Product: gcc
Version: 12.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: orgads at gmail dot com
Target Milestone: ---
This is the most minimal repro I could create:
struct List {
void *f1 = nullptr;
void *f2 = nullptr;
};
class Base {
public:
virtual ~Base() {}
virtual void foo() = 0;
};
class Derived1 : public Base {
char buf[10];
public:
Derived1() {}
~Derived1() override {}
void foo() override;
};
class Derived2 : public Base {
public:
Derived2();
~Derived2();
void foo() override;
};
void test()
{
Base *update = new Derived2();
List list;
delete update;
}
When compiling with -fcheck-new -Wall -O2, the following error is shown:
In destructor 'virtual Derived1::~Derived1()',
inlined from 'virtual Derived1::~Derived1()' at :17:24,
inlined from 'void test()' at :32:9:
:17:31: warning: array subscript 'Derived1::__as_base [0]' is partly
outside array bounds of 'unsigned char [8]' [-Warray-bounds=]
17 | ~Derived1() override {}
| ^
: In function 'void test()':
:30:37: note: object of size 8 allocated by 'operator new'
30 | Base *update = new Derived2();
|
This looks similar to bug 106247 and some others.
Godbolt link: https://godbolt.org/z/Pa8xh5T5n