diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -768,7 +768,7 @@ ArrayRef List = internal::getTemplateSpecializationArgs(Node); return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder, - Builder); + Builder) != List.end(); } /// Causes all nested matchers to be matched with the specified traversal kind. @@ -3107,7 +3107,8 @@ AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.method_begin(), - Node.method_end(), Finder, Builder); + Node.method_end(), Finder, + Builder) != Node.method_end(); } /// Matches the generated class of lambda expressions. @@ -3883,7 +3884,8 @@ AST_MATCHER_P(OverloadExpr, hasAnyDeclaration, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.decls_begin(), - Node.decls_end(), Finder, Builder); + Node.decls_end(), Finder, + Builder) != Node.decls_end(); } /// Matches the Decl of a DeclStmt which has a single declaration. @@ -4153,7 +4155,8 @@ AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.init_begin(), - Node.init_end(), Finder, Builder); + Node.init_end(), Finder, + Builder) != Node.init_end(); } /// Matches the field declaration of a constructor initializer. @@ -4599,7 +4602,8 @@ internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(), - Node.param_end(), Finder, Builder); + Node.param_end(), Finder, + Builder) != Node.param_end(); } /// Matches \c FunctionDecls and \c FunctionProtoTypes that have a @@ -5040,7 +5044,8 @@ internal::Matcher, InnerMatcher) { const CompoundStmt *CS = CompoundStmtMatcher::get(Node); return CS && matchesFirstInPointerRange(InnerMatcher, CS->body_begin(), - CS->body_end(), Finder, Builder); + CS->body_end(), Finder, + Builder) != CS->body_end(); } /// Checks that a compound statement contains a specific number of @@ -5882,7 +5887,8 @@ AST_MATCHER_P(UsingDecl, hasAnyUsingShadowDecl, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.shadow_begin(), - Node.shadow_end(), Finder, Builder); + Node.shadow_end(), Finder, + Builder) != Node.shadow_end(); } /// Matches a using shadow declaration where the target declaration is @@ -7438,7 +7444,8 @@ internal::Matcher, InnerMatcher) { ArrayRef Clauses = Node.clauses(); return matchesFirstInPointerRange(InnerMatcher, Clauses.begin(), - Clauses.end(), Finder, Builder); + Clauses.end(), Finder, + Builder) != Clauses.end(); } /// Matches OpenMP ``default`` clause. 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 @@ -636,33 +636,33 @@ /// Finds the first node in a range that matches the given matcher. template -bool matchesFirstInRange(const MatcherT &Matcher, IteratorT Start, - IteratorT End, ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) { +IteratorT matchesFirstInRange(const MatcherT &Matcher, IteratorT Start, + IteratorT End, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) { for (IteratorT I = Start; I != End; ++I) { BoundNodesTreeBuilder Result(*Builder); if (Matcher.matches(*I, Finder, &Result)) { *Builder = std::move(Result); - return true; + return I; } } - return false; + return End; } /// Finds the first node in a pointer range that matches the given /// matcher. template -bool matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start, - IteratorT End, ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) { +IteratorT matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start, + IteratorT End, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) { for (IteratorT I = Start; I != End; ++I) { BoundNodesTreeBuilder Result(*Builder); if (Matcher.matches(**I, Finder, &Result)) { *Builder = std::move(Result); - return true; + return I; } } - return false; + return End; } // Metafunction to determine if type T has a member called getDecl.