================
@@ -2642,11 +2640,25 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool
UseGlobal,
// are required for delete[] call but MSVC triggers emission of them
// whenever new[] is called for an object of the class and we do the same
// for compatibility.
- if (const CXXConstructExpr *CCE =
- dyn_cast_or_null<CXXConstructExpr>(Initializer);
- CCE && ArraySize) {
- Context.setClassNeedsVectorDeletingDestructor(
- CCE->getConstructor()->getParent());
+ if (Context.getTargetInfo().emitVectorDeletingDtors(Context.getLangOpts())) {
+ if (const CXXConstructExpr *CCE =
+ dyn_cast_or_null<CXXConstructExpr>(Initializer);
+ CCE && ArraySize) {
+ CXXRecordDecl *ClassDecl = CCE->getConstructor()->getParent();
+ auto *Dtor = ClassDecl->getDestructor();
+ if (Dtor && Dtor->isVirtual() && !Dtor->isDeleted()) {
+ Context.setClassNeedsVectorDeletingDestructor(ClassDecl);
+ if (!Dtor->isDefined() && !Dtor->isInvalidDecl()) {
+ // Call CheckDestructor even if Destructor is not defined. This is
+ // needed to find operators delete and delete[] for vector deleting
+ // destructor body because new[] will trigger emission of vector
+ // deleting destructor body even if destructor is defined in another
+ // translation unit.
----------------
Fznamznon wrote:
`Sema::MarkVTableUsed` will do the call to `CheckDestructor`, sure and it will
work but it will also do something with vtable and other virtual members which
I'm not sure should be done for the case since I don't see msvc even emitting
vtable for a class that has only declared constructor, destructor and new[] is
called, though the vector deleting destructor is emitted.
https://godbolt.org/z/MdG1qh7Wd
https://github.com/llvm/llvm-project/pull/185653
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits