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



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to