[PATCH] D21298: [Clang-tidy] delete null check
Gergely Angeli via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 17 14:02:30 PST 2016
SilverGeri added inline comments.
================
Comment at: test/clang-tidy/readability-delete-null-pointer.cpp:7
+ int *p = 0;
+ if (p) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
----------------
aaron.ballman wrote:
> hokein wrote:
> > Does it work the case like:
> >
> > ```
> > int *p = nullptr;
> > if (p == nullptr) {
> > p = new int[3];
> > delete[] p;
> > }
> > ```
> >
> > ?
> Similarly, it should not mishandle a case like:
>
> void f(int *p) {
> if (p) {
> delete p;
> } else {
> // Do something else
> }
> }
it warns only if the compund statement contains only one statement (which is the delete). We want to warn because it is unnecessary to check the pointer validity if you want to just call `delete`. In other cases, we can't be sure about the actual behaviour.
https://reviews.llvm.org/D21298
More information about the cfe-commits
mailing list