[clang] [win][clang] Align scalar deleting destructors with MSABI (PR #139566)

Tom Honermann via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 13 21:18:12 PDT 2025


================
@@ -11139,6 +11139,21 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
       DiagnoseUseOfDecl(OperatorDelete, Loc);
       MarkFunctionReferenced(Loc, OperatorDelete);
       Destructor->setOperatorDelete(OperatorDelete, ThisArg);
+
+      if (isa<CXXMethodDecl>(OperatorDelete) &&
+          Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+        // In Microsoft ABI whenever a class has a defined operator delete,
+        // scalar deleting destructors check the 3rd bit of the implicit
+        // parameter and if it is set, then, global operator delete must be
+        // called instead of class-specific one. Find and save global operator
+        // for that case. Do not diagnose because even if we fail to find the
+        // operator, it won't be possible to compile and execute the code that
+        // requires it.
----------------
tahonermann wrote:

Suggested edits.
```suggestion
        // In Microsoft ABI whenever a class has a defined operator delete,
        // scalar deleting destructors check the 3rd bit of the implicit
        // parameter and if it is set, then, global operator delete must be
        // called instead of the class-specific one. Find and save the global operator
        // delete for that case. Do not diagnose at this point because the
        // lack of a global operator delete is not an error if there are no
        // delete calls that require it.
```

https://github.com/llvm/llvm-project/pull/139566


More information about the cfe-commits mailing list