[clang] [RFC] Initial implementation of P2719 (PR #113510)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 31 21:48:55 PDT 2025
================
@@ -1098,12 +1098,39 @@ static TypeSourceInfo *getTypeSourceInfoForStdAlignValT(Sema &S,
return S.Context.getTrivialTypeSourceInfo(StdAlignValDecl);
}
+// When searching for custom allocators on the PromiseType we want to
+// warn that we will ignore type aware allocators.
+static bool DiagnoseTypeAwareAllocators(Sema &S, SourceLocation Loc,
+ unsigned DiagnosticID,
+ DeclarationName Name,
+ QualType PromiseType) {
+ assert(PromiseType->isRecordType());
+
+ LookupResult R(S, Name, Loc, Sema::LookupOrdinaryName);
+ S.LookupQualifiedName(R, PromiseType->getAsCXXRecordDecl());
+ bool HaveIssuedWarning = false;
+ for (auto Decl : R) {
+ if (!Decl->getAsFunction()->isTypeAwareOperatorNewOrDelete())
+ continue;
+ if (!HaveIssuedWarning) {
+ S.Diag(Loc, DiagnosticID) << Name;
+ HaveIssuedWarning = true;
+ }
+ S.Diag(Decl->getLocation(), diag::note_type_aware_operator_declared)
+ << /* isTypeAware */ 1 << Decl << Decl->getDeclContext();
----------------
ojhunt wrote:
Mercifully for P2719 the semantically relevant location is the declaration scope is the scope of the original function declaration and there's now a test that:
```cpp
struct A { operator new ...; operator delete ...; }
struct B { operator new ...; operator delete ...; }
struct C : A, B {
using A::operator new;
using B::operator delete;
};
```
is detected as invalid due to new and delete coming from different scopes.
https://github.com/llvm/llvm-project/pull/113510
More information about the cfe-commits
mailing list