[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 25 11:40:47 PDT 2017
erichkeane updated this revision to Diff 120289.
erichkeane added a comment.
Lets ignore parens too!
https://reviews.llvm.org/D39301
Files:
lib/Sema/Sema.cpp
test/SemaCXX/warn-zero-nullptr.cpp
Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -438,7 +438,7 @@
void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
return;
- if (E->getType()->isNullPtrType())
+ if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
return;
// nullptr only exists from C++11 on, so don't warn on its absence earlier.
if (!getLangOpts().CPlusPlus11)
Index: test/SemaCXX/warn-zero-nullptr.cpp
===================================================================
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,9 @@
// Warn on these too. Matches gcc and arguably makes sense.
void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}}
void* pp2 = static_cast<decltype(nullptr)>(0); // expected-warning{{zero as null pointer constant}}
+
+// Shouldn't warn.
+namespace pr34362 {
+struct A { operator int*() { return nullptr; } };
+void func () { if (nullptr == A()) {} }
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39301.120289.patch
Type: text/x-patch
Size: 1132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171025/88501aae/attachment.bin>
More information about the cfe-commits
mailing list