Trouble to use MatchFinder::match


I’m a software developer and in my company we use clang to parse c++ code.

I’m in trouble to go to a call back when I’m using an AST matcher.

Here is the problem:

I already use the function “ clang::ast_matchers::MatchFinder::matchAST(ASTContext&)” and it works perfectly. But, in a particular case, I would like to match only within a subtree so I try to use “ clang::ast_matchers::MatchFinder::match(constT &node, ASTContext&)” but I never reach my callback.

Here a sample of a source code

clang::ast_matchers::MatchFinder matcherFinder;

matcherFinder.addMatcher(binaryOperatorMatcher, new MatchCallback(

[&cleanListField](cla::MatchFinder::MatchResult const & matchRes)


auto binaryOperator = matchRes.Nodes.getNodeAsclang::Stmt(binaryOperatorNode);



matcherFinder.match((*constructor), constructor->getASTContext());


As we can see in the example, the subtree root is a clang::CXXConstructorDecl.

Thanks you in advance.

Best regards.

Anthony LEFORT

Software engineer

3 rue Marcel Allégot

92190 Meudon - France

CAST, Leader in Automated Application Intelligence

Achieve Insight. Deliver Excellence. | Gain visibility into application quality to proactively manage risk and improve team performance.

If a matcher is applied to concrete AST node instead of the whole context, it matches strictly this given node. To match child nodes, enclose your matcher with hasDescendant() or forEachDescendant() matcher.

28.04.2017 19:37, Anthony Lefort via cfe-dev пишет: