[cfe-dev] Potentially expensive analysis for missing `[]` in delete expression
Ismail Pazarbasi
ismail.pazarbasi at gmail.com
Tue Jul 8 09:57:09 PDT 2014
Hi,
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:
class A {
int *a;
public:
A() : a(new int[5]) { }
~A() { delete /*[]*/ a; }
};
but following doesn't seem like to analyze missing [] either:
% clang++ -fsyntax-only -x c++ -pedantic -Wall -Wextra -
void f() {
int *a = new int[5];
delete a;
}
%
Is this analysis omitted due to performance concerns or simply an oversight?
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?
Ismail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140708/c93b05c6/attachment.html>
More information about the cfe-dev
mailing list