Skip to content

Implement vector deleting destructors #19772

@rnk

Description

@rnk
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ABIApplication Binary InterfacebugzillaIssues migrated from bugzillac++clang:codegenIR generation bugs: mangling, exceptions, etc.clang:frontendLanguage frontend issues, e.g. anything involving "Sema"extension:microsoft

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions