Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -601,13 +601,55 @@ Registry::getMatchingMatchers(ast_type_traits::ASTNodeKind StaticType) { std::vector Result; + // Exclude matchers which can't unambiguously + // be used with particular arguments. + static std::vector ExcludedMatchers{ + "allOf", + "anyOf", + "anything", + "containsDeclaration", + "eachOf", + "equalsNode", + "findAll", + "forEach", + "forEachConstructorInitializer", + "forEachDescendant", + "forEachOverridden", + "forEachSwitchCase", + "has", + "hasAncestor", + "hasAnyArgument", + "hasAnyConstructorInitializer", + "hasAnyDeclaration", + "hasAnyName", + "hasAnyParameter", + "hasAnySelector", + "hasAnySubstatement", + "hasAnyTemplateArgument", + "hasAnyUsingShadowDecl", + "hasArgumentOfType", + "hasDescendant", + "hasEitherOperand", + "hasMethod", + "hasParent", + "isExpansionInFileMatching", + "isSameOrDerivedFrom", + "matchesName", + "matchesSelector", + "unless"}; + assert(std::is_sorted(ExcludedMatchers.begin(), ExcludedMatchers.end())); + std::vector AcceptedTypes{StaticType}; processAcceptableMatchers( - AcceptedTypes, - [&Result](StringRef Name, const MatcherDescriptor &, - std::set &, std::vector>, - unsigned) { Result.emplace_back((Name + "()").str()); }); + AcceptedTypes, [&Result](StringRef Name, const MatcherDescriptor &, + std::set &, + std::vector>, unsigned) { + if (!std::binary_search(ExcludedMatchers.begin(), + ExcludedMatchers.end(), Name)) { + Result.emplace_back((Name + "()").str()); + } + }); return Result; } Index: unittests/ASTMatchers/Dynamic/RegistryTest.cpp =================================================================== --- unittests/ASTMatchers/Dynamic/RegistryTest.cpp +++ unittests/ASTMatchers/Dynamic/RegistryTest.cpp @@ -579,6 +579,8 @@ EXPECT_TRUE(!Contains(Matchers, "functionDecl()")); EXPECT_TRUE(Contains(Matchers, "cxxMethodDecl()")); + + EXPECT_TRUE(!Contains(Matchers, "has()")); } } // end anonymous namespace