diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2308,15 +2308,25 @@ return true; } -// This method is called once for each pair of syntactic and semantic -// InitListExpr, and it traverses the subtrees defined by the two forms. This -// may cause some of the children to be visited twice, if they appear both in -// the syntactic and the semantic form. +// If shouldVisitImplicitCode() returns false, this method traverses only the +// syntactic form of InitListExpr. +// If shouldVisitImplicitCode() return true, this method is called once for +// each pair of syntactic and semantic InitListExpr, and it traverses the +// subtrees defined by the two forms. This may cause some of the children to be +// visited twice, if they appear both in the syntactic and the semantic form. // // There is no guarantee about which form \p S takes when this method is called. template bool RecursiveASTVisitor::TraverseInitListExpr( InitListExpr *S, DataRecursionQueue *Queue) { + if (!getDerived().shouldVisitImplicitCode()) { + // Visit only the syntactic form if the clients are not interested in + // implicit compiler-generated semantic form. + TRY_TO(TraverseSynOrSemInitListExpr( + S->isSyntacticForm() ? S : S->getSyntacticForm(), Queue)); + return true; + } + TRY_TO(TraverseSynOrSemInitListExpr( S->isSemanticForm() ? S->getSyntacticForm() : S, Queue)); TRY_TO(TraverseSynOrSemInitListExpr(