<div dir="ltr">Hi,<br>
<br>During a demo, audience caught that I forgot [] in delete expression. clang didn't warn about it. I was wondering whether this is due to the cost of analysis. My sample was something like:<br>
<br>
class A {<br>
int *a;<br>
public:<br>
A() : a(new int[5]) { }<br>
~A() { delete /*[]*/ a; }<br>
};<br>
<br>but following doesn't seem like to analyze missing [] either:<div><br><div> % clang++ -fsyntax-only -x c++ -pedantic -Wall -Wextra -</div><div><div> void f() {</div><div> int *a = new int[5];</div><div> delete a;</div>
<div> }</div> %</div><div><br></div><div>Is this analysis omitted due to performance concerns or simply an oversight?</div><div><br>Analyzing my sample requires clang to analyze all ctor-initializers, then in-class initializers, to check whether member was new[]'ed each time it sees delete expression where pointee is a MemberExpr. For the latter case, I think checking whether VarDecl initialized with new[] is enough. Did I get this right? I already have a patch for this, but I didn't test its performance impact on a sufficiently large code base. Do we have previous implementation experience with this?<br>
</div></div><div><br></div><div>Ismail</div></div>