| Issue |
115585
|
| Summary |
delete[] does not call the destructor correctly
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
tangpanyu
|
```#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
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs