[clang] One more fix for P3144R2 implementation (PR #149406)
Harald van Dijk via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 22 16:49:02 PDT 2025
================
@@ -595,6 +595,10 @@ struct GH99278_2 {
} f;
};
GH99278_2<void> e;
+void GH99278_3(int(*p)[]) {
+ delete p;
+ // expected-warning at -1 {{'delete' applied to a pointer-to-array type 'int (*)[]' treated as 'delete[]'}}
+};
----------------
hvdijk wrote:
> The general issue here is that there's a hole in the standard: a non-array new-expression can't return a pointer to an array, so [expr.delete]p2 effectively says it's always undefined behavior to delete a pointer to an array (unless it's null).
True for the tests that I added with `delete`. For your example with `delete[]`, consider:
```c++
struct S { ~S(); };
void del(S(*p)[]) { delete[] p; }
void test() { del(new S[4][4]); }
```
The checks that I implemented in this PR handle this, they allow it in that test, but reject it if `S` is incomplete which is necessary to avoid UB.
The codegen crash is worrying, the test I'm showing here shows that this can occur in legitimate code. I'll have a look at that when I have some extra time.
https://github.com/llvm/llvm-project/pull/149406
More information about the cfe-commits
mailing list