[clang] [Clang] Improve diagnostics for 'placement new' with const storage argument (PR #144270)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 22 13:08:04 PDT 2025


================
@@ -2753,10 +2753,18 @@ static bool resolveAllocationOverloadInterior(
     if (Diagnose) {
       // If this is an allocation of the form 'new (p) X' for some object
       // pointer p (or an expression that will decay to such a pointer),
-      // diagnose the missing inclusion of <new>.
+      // diagnose potential error.
       if (!R.isClassLookup() && Args.size() == 2 &&
           (Args[1]->getType()->isObjectPointerType() ||
            Args[1]->getType()->isArrayType())) {
+        if (Args[1]->getType()->isPointerType()) {
----------------
vbvictor wrote:

> should probably be earlier - this is inside an array of object check

We have `isObjectPointerType() || isArrayType()` in first `if`, so pointer are handled correctly, I added tests for that.

I used `Context.getBaseElementType()`, but still had to manually check for pointer because it only unwraps arrays. 

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


More information about the cfe-commits mailing list