[clang] [RFC] Initial implementation of P2719 (PR #113510)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 30 10:24:05 PDT 2025
================
@@ -16439,33 +16735,70 @@ CheckOperatorDeleteDeclaration(Sema &SemaRef, FunctionDecl *FnDecl) {
return true;
auto *MD = dyn_cast<CXXMethodDecl>(FnDecl);
+ auto ConstructDestroyingDeleteAddressType = [&]() {
+ assert(MD);
+ return SemaRef.Context.getCanonicalType(SemaRef.Context.getPointerType(
+ SemaRef.Context.getRecordType(MD->getParent())));
+ };
+
+ // C++ P2719: A destroying operator delete cannot be type aware
+ // so for QoL we actually check for this explicitly by considering
+ // an destroying-delete appropriate address type and the presence of
+ // any parameter of type destroying_delete_t as an erroneous attempt
+ // to declare a type aware destroying delete, rather than emitting a
+ // pile of incorrect parameter type errors.
+ if (MD && IsPotentiallyTypeAwareOperatorNewOrDelete(
+ SemaRef, MD, /*WasMalformed=*/nullptr)) {
+ QualType AddressParamType =
+ SemaRef.Context.getCanonicalType(MD->getParamDecl(1)->getType());
+ if (AddressParamType != SemaRef.Context.VoidPtrTy &&
+ AddressParamType == ConstructDestroyingDeleteAddressType()) {
+ // The address parameter type implies an author trying to construct a
+ // type aware destroying delete, so we'll see if we can find a parameter
+ // of type `std::destroying_delete_t`, and if we find it we'll report
+ // this as being an attempt at a type aware destroying delete just stop
+ // here. If we don't do this, the resulting incorrect parameter ordering
+ // results in a pile mismatched argument type errors that don't explain
+ // the core problem.
+ for (auto Param : MD->parameters()) {
+ if (isDestroyingDeleteT(Param->getType())) {
+ SemaRef.Diag(MD->getLocation(),
+ diag::err_type_aware_destroying_operator_delete)
+ << Param->getLocation();
----------------
mizvekov wrote:
```suggestion
SemaRef.Diag(MD->getLocation(),
diag::err_type_aware_destroying_operator_delete)
<< Param->getSourceRange();
```
https://github.com/llvm/llvm-project/pull/113510
More information about the cfe-commits
mailing list