[PATCH] D32914: Introduce Wzero-as-null-pointer-constant.
Hans Wennborg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 5 09:14:44 PDT 2017
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.
Nice. Some comments, but lgtm.
================
Comment at: include/clang/Sema/Sema.h:3760
+ /// \brief Warn when implicitly casting 0 to nullptr.
+ void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E);
----------------
\brief is redudant here I believe and doesn't seem used for the surrounding functions.
================
Comment at: lib/Sema/Sema.cpp:396
+ Diag(E->getLocStart(), diag::warn_zero_as_null_pointer_constant)
+ << FixItHint::CreateReplacement(E->getSourceRange(), "nullptr");
+}
----------------
I was about to say that a fixit would be nice, but you were way ahead of me :-)
================
Comment at: test/SemaCXX/warn-zero-nullptr.cpp:9
+int (S::*mp1) = 0; // expected-warning{{zero as null pointer constant}}
+void* p1 = 0; // expected-warning{{zero as null pointer constant}}
+
----------------
If I understand the code correctly, the warning will fire for function pointers too because that's also CK_NullToPointer. May be worth adding to the test anyway though.
https://reviews.llvm.org/D32914
More information about the cfe-commits
mailing list