Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -5536,7 +5536,8 @@ /// matches "A::" AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc, internal::Matcher, InnerMatcher) { - return Node && InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder); + return Node && Node.getNestedNameSpecifier()->getAsType() && + InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder); } /// Matches on the prefix of a \c NestedNameSpecifier. Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1450,6 +1450,10 @@ "struct A { struct B { struct C {}; }; }; A::B::C c;", nestedNameSpecifierLoc(hasPrefix( specifiesTypeLoc(loc(qualType(asString("struct A")))))))); + EXPECT_TRUE(matches( + "namespace N { struct A { struct B { struct C {}; }; }; } N::A::B::C c;", + nestedNameSpecifierLoc(hasPrefix( + specifiesTypeLoc(loc(qualType(asString("struct N::A")))))))); }