[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:18:16 PDT 2017
erichkeane created this revision.
The repro in https://bugs.llvm.org/show_bug.cgi?id=34362
caused the left nullptr to be cast to a int* implicitly, which
resulted diagnosing this falsely.
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->IgnoreImpCasts()->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,7 @@
// 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.
+struct pr34362 { operator int*() { return nullptr; } };
+void pr34362_func() { if (nullptr == pr34362()) {} }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39301.120286.patch
Type: text/x-patch
Size: 1122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171025/bd6acc4b/attachment.bin>
More information about the cfe-commits
mailing list