[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 13:23:48 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL316605: Ignore implicity casts for zero-as-null-pointer-constant warning (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D39301?vs=120289&id=120301#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39301

Files:
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/test/SemaCXX/warn-zero-nullptr.cpp


Index: cfe/trunk/test/SemaCXX/warn-zero-nullptr.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-zero-nullptr.cpp
+++ cfe/trunk/test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,10 @@
 // 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()) {} }
+void func2() { if ((nullptr) == A()) {} }
+}
Index: cfe/trunk/lib/Sema/Sema.cpp
===================================================================
--- cfe/trunk/lib/Sema/Sema.cpp
+++ cfe/trunk/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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39301.120301.patch
Type: text/x-patch
Size: 1235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171025/0cd07676/attachment.bin>


More information about the cfe-commits mailing list