Index: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp @@ -200,12 +200,14 @@ return true; } - if (!FirstSubExpr) - FirstSubExpr = C->getSubExpr()->IgnoreParens(); - - // Ignore the expr if it is already a nullptr literal expr. - if (isa(FirstSubExpr)) + auto* CastSubExpr = C->getSubExpr()->IgnoreParens(); + // Ignore cast expressions which cast nullptr literal. + if (isa(CastSubExpr)) { return true; + } + + if (!FirstSubExpr) + FirstSubExpr = CastSubExpr; if (C->getCastKind() != CK_NullToPointer && C->getCastKind() != CK_NullToMemberPointer) { Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp @@ -261,3 +261,17 @@ void IgnoreSubstTemplateType() { TemplateClass a(1); } + +// Test on casting nullptr. +struct G { + explicit G(bool, const char * = NULL) {} + // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use nullptr + // CHECK-FIXES: explicit G(bool, const char * = nullptr) {} +}; +bool g(const char*); +void test_cast_nullptr() { + G(g(nullptr)); + G(g((nullptr))); + G(g(static_cast(nullptr))); + G(g(static_cast(nullptr))); +}