Skip to content

Commit 818cf5b

Browse files
author
Erich Keane
committedOct 25, 2017
Ignore implicity casts for zero-as-null-pointer-constant warning
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. Differential Revision: https://reviews.llvm.org/D39301 llvm-svn: 316605
1 parent cc7763b commit 818cf5b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

Diff for: ‎clang/lib/Sema/Sema.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void Sema::diagnoseNullableToNonnullConversion(QualType DstType,
438438
void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
439439
if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
440440
return;
441-
if (E->getType()->isNullPtrType())
441+
if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
442442
return;
443443
// nullptr only exists from C++11 on, so don't warn on its absence earlier.
444444
if (!getLangOpts().CPlusPlus11)

Diff for: ‎clang/test/SemaCXX/warn-zero-nullptr.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ void g() {
2525
// Warn on these too. Matches gcc and arguably makes sense.
2626
void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}}
2727
void* pp2 = static_cast<decltype(nullptr)>(0); // expected-warning{{zero as null pointer constant}}
28+
29+
// Shouldn't warn.
30+
namespace pr34362 {
31+
struct A { operator int*() { return nullptr; } };
32+
void func() { if (nullptr == A()) {} }
33+
void func2() { if ((nullptr) == A()) {} }
34+
}

0 commit comments

Comments
 (0)
Please sign in to comment.