Description
Bugzilla Link | 19398 |
Version | unspecified |
OS | Windows NT |
Blocks | #12849 |
CC | @majnemer,@timurrrr |
Extended Description
MSVC supports an extension that allows users to delete an array of polymorphic objects where the dynamic type doesn't match the static type of the array.
Here's an example of MSVC doing this where we can't:
$ cat t.cpp
extern "C" int printf(const char *, ...);
struct A {
A() : a(42) {}
virtual ~A() { printf("a: %d\n", a); }
int a;
};
struct B : A {
B() : b(13) {}
~B() { printf("b: %d\n", b); }
int b;
};
void foo(A *a) { delete[] a; }
int main() {
B *b = new B[2];
foo(b);
}
$ cl -nologo t.cpp && ./t.exe
t.cpp
b: 13
a: 42
b: 13
a: 42
$ clang-cl t.cpp && ./t.exe
a: 16699704
a: 42
They use "vector deleting destructors" to do this special array deletion, and those are what go in the vftable. We currently put the scalar deleting dtor there instead.