================ @@ -7353,6 +7354,69 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) { else if (Record->hasAttr<CUDADeviceBuiltinTextureTypeAttr>()) checkCUDADeviceBuiltinTextureClassTemplate(*this, Record); } + + llvm::SmallVector<const FunctionDecl *, 2> TypeAwareNewDecls; + llvm::SmallVector<const FunctionDecl *, 2> TypeAwareDeleteDecls; + llvm::SmallVector<const FunctionDecl *, 2> TypeAwareArrayNewDecls; + llvm::SmallVector<const FunctionDecl *, 2> TypeAwareArrayDeleteDecls; + + for (auto *D : Record->decls()) { + const FunctionDecl *FnDecl = nullptr; + if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) + FnDecl = FTD->getTemplatedDecl(); + else if (auto *FD = dyn_cast<FunctionDecl>(D)) + FnDecl = FD; + if (!FnDecl || !FnDecl->isTypeAwareOperatorNewOrDelete()) + continue; + switch (FnDecl->getOverloadedOperator()) { + case OO_New: + TypeAwareNewDecls.push_back(FnDecl); + break; + case OO_Array_New: + TypeAwareArrayNewDecls.push_back(FnDecl); + break; + case OO_Delete: + TypeAwareDeleteDecls.push_back(FnDecl); + break; + case OO_Array_Delete: + TypeAwareArrayDeleteDecls.push_back(FnDecl); + break; + default: + continue; + } + } + auto CheckMismatchedTypeAwareAllocators = + [this, + Record](OverloadedOperatorKind NewKind, + const llvm::SmallVector<const FunctionDecl *, 2> &NewDecls, + OverloadedOperatorKind DeleteKind, + const llvm::SmallVector<const FunctionDecl *, 2> &DeleteDecls) { + if (NewDecls.empty() == DeleteDecls.empty()) + return; + DeclarationName FoundOperator = + Context.DeclarationNames.getCXXOperatorName( + NewDecls.empty() ? DeleteKind : NewKind); + DeclarationName MissingOperator = + Context.DeclarationNames.getCXXOperatorName( + NewDecls.empty() ? NewKind : DeleteKind); + Diag(Record->getLocation(), + diag::err_type_aware_allocator_missing_matching_operator) + << FoundOperator << Context.getRecordType(Record) + << MissingOperator; ---------------- ojhunt wrote:
> Is it possible to get here with an anonymous class? If so, then you might > need a 'this class' fallback as well. I initially thought no because anonymous templates aren't a thing, but then I realized that an anonymous class can have template members, so I'll add a test in a moment, and I suspect there's a non-zero chance that the diagnostic will crash :( https://github.com/llvm/llvm-project/pull/113510 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits