diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -1064,10 +1064,11 @@ /// is \c NULL. bool matchesDecl(const Decl *Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const { - if (Finder->isTraversalIgnoringImplicitNodes() && Node->isImplicit()) - return false; - return Node != nullptr && this->InnerMatcher.matches( - DynTypedNode::create(*Node), Finder, Builder); + return Node != nullptr && + !(Finder->isTraversalIgnoringImplicitNodes() && + Node->isImplicit()) && + this->InnerMatcher.matches(DynTypedNode::create(*Node), Finder, + Builder); } }; diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -1935,6 +1935,18 @@ matches(Code, callExpr(traverse(TK_IgnoreUnlessSpelledInSource, hasAnyArgument(floatLiteral()))))); + EXPECT_TRUE(matches( + R"cpp( +void takesBool(bool){} + +template +void neverInstantiatedTemplate() { + takesBool(T{}); +} +)cpp", + traverse(TK_IgnoreUnlessSpelledInSource, + callExpr(unless(callExpr(hasDeclaration(functionDecl()))))))); + EXPECT_TRUE( matches(VarDeclCode, varDecl(traverse(TK_IgnoreUnlessSpelledInSource, hasType(builtinType())))));