<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115585>115585</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
delete[] does not call the destructor correctly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tangpanyu
</td>
</tr>
</table>
<pre>
```#include <iostream>
using namespace std;
class A {
private:
int a;
public:
A(int a): a(a) {
cout << "A::A() at " << this << endl;
}
virtual ~A() { // 声明为虚函数
cout << "A::~A() at " << this << endl;
}
};
class B : public A {
private:
int* b;
public:
B() : A(0) {
b = new int(2);
cout << "B::B() at " << this << endl;
}
~B() {
delete b;
cout << "B::~B() at " << this << endl;
}
};
int main() {
A* b = new B[3];
delete[] b;
return 0;
}
```
output:
```A::A() at 0x558244795eb8
B::B() at 0x558244795eb8
A::A() at 0x558244795ed0
B::B() at 0x558244795ed0
A::A() at 0x558244795ee8
B::B() at 0x558244795ee8
A::~A() at 0x558244795ed8
A::~A() at 0x558244795ec8
A::~A() at 0x558244795eb8
```
delete[] does not call the destructor correctly
clang++ version:
clang version 19.0.0git (https://github.com/llvm/llvm-project.git ce80c80dca45c7b4636a3e143973e2c6cbdb2884)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/llvm/bin
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVUuP6yYY_TVfNmgiDH4uvLBvEqn77isM33VoCY545M5s8tsr7Dxu7kynaSeKZOA7HI7PASy816NFbKHoodisRAz7ybVB2PEo7FtcDZN6a6Gklz_j2koTFRLg3_Tkg0NxAL4FugHaRa_tSKw4oD8KicQHBbxfatII70lHoLoMHJ0-iYDAu6VPCCHaBiJuUy64OBgtH2AdsHqBsgZ4l551at_JyeUnpxiSVODfCDDWJRrepfkJLkIavNbDXvtrG60yNx2JCKrNvXPSLkRhyPlKBFVPCLAdsB2BbQEdh57CtoSmhnoL2xz6GvoOtjU0DTRdwtQV9JsZUyTwE7LPX9GdGo_GLon0JDm4mPxEPMA6Mvx7Qv3VGN7NadEP0xkI8A2x-GNhrtmc5-cR9osX_RcjPPf36B7XU2gw4E8v-bmQ81eU_BxK2tAHoe1HurrZ9ptbPRQ9h2LzQLroXs7xL-odhugsoffcbgJuJ3vuTjEcY7gleau-Pzf0tShqludVU-BQL_D30XyE-pxL0We4rqjPufApXfio6_xPwp6DyedgVzN-8f8hQzWhJ3YKRApjSNgjUeiDizJMjsjJOZTBvN3Osh2B9cB6ckLn9WRvKc616yjJmjVd01Gn3VrvQzj6BJyvrlGHfRzWcjoA2xlzuj5ejm76E2VYp1kSayprqqTIC1kNeclLwTHLeVNxZLKUgxpYXefpKM_L_y7ciGlPkde6_KPMX6L9y04_7IvRNr6-jDZecHuHQpHDpNDMV9Lk9etS-s36IIxBtdEulYDtondJ3SSFuYsdtF2plquGN2KFbVbxLOOMNtVq31b4nedYyUFWWVk0dMhoqfKqyBssctWolW4ZZXmW0YaWNOPVeuCibmj5PS9kRqkcIKd4ENqs02rryY0r7X3ENsuKoi5WRgxo_PwhZWy-01IVGEvfVdfORg5x9JBTo33wd5qgg8H2f2S_is60_y1DYLtZlwe2uwg_tezvAAAA__8FthrP">