Index: clang-tidy/modernize/UseNullptrCheck.cpp =================================================================== --- clang-tidy/modernize/UseNullptrCheck.cpp +++ clang-tidy/modernize/UseNullptrCheck.cpp @@ -435,12 +435,14 @@ Loc = D->getLocStart(); else if (const auto *S = Parent.get()) Loc = S->getLocStart(); - else - llvm_unreachable("Expected to find Decl or Stmt containing ancestor"); - if (!expandsFrom(Loc, MacroLoc)) { - Result = Parent; - return true; + // TypeLoc and NestedNameSpecifierLoc are members of the parent map. Skip + // them and keep going up. + if (Loc.isValid()) { + if (!expandsFrom(Loc, MacroLoc)) { + Result = Parent; + return true; + } } Start = Parent; } Index: test/clang-tidy/modernize-use-nullptr.cpp =================================================================== --- test/clang-tidy/modernize-use-nullptr.cpp +++ test/clang-tidy/modernize-use-nullptr.cpp @@ -184,3 +184,15 @@ // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}}; #undef ENTRY } + +// One of the ancestor of the cast is a NestedNameSpecifierLoc. +class NoDef; +char function(NoDef *p); +#define F(x) \ + (sizeof(function(x)) == 1) +template +class C {}; +C c; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr +// CHECK-FIXES: C c; +#undef F