diff options
| -rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchFinder.h | 12 | ||||
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 8 |
2 files changed, 9 insertions, 11 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchFinder.h b/clang/include/clang/ASTMatchers/ASTMatchFinder.h index 8af0546db57..9e90270dcf6 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchFinder.h +++ b/clang/include/clang/ASTMatchers/ASTMatchFinder.h @@ -210,16 +210,14 @@ match(MatcherT Matcher, const ast_type_traits::DynTypedNode &Node, /// /// This is useful in combanation with \c match(): /// \code -/// Decl *D = selectFirst<Decl>("id", match(Matcher.bind("id"), -/// Node, Context)); +/// const Decl *D = selectFirst<Decl>("id", match(Matcher.bind("id"), +/// Node, Context)); /// \endcode template <typename NodeT> -NodeT * +const NodeT * selectFirst(StringRef BoundTo, const SmallVectorImpl<BoundNodes> &Results) { - for (SmallVectorImpl<BoundNodes>::const_iterator I = Results.begin(), - E = Results.end(); - I != E; ++I) { - if (NodeT *Node = I->getNodeAs<NodeT>(BoundTo)) + for (const BoundNodes &N : Results) { + if (const NodeT *Node = N.getNodeAs<NodeT>(BoundTo)) return Node; } return nullptr; diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index bd7a5a6df8f..d4f867114e9 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4163,8 +4163,8 @@ public: virtual bool run(const BoundNodes *Nodes, ASTContext *Context) { const T *Node = Nodes->getNodeAs<T>(Id); - return selectFirst<const T>(InnerId, - match(InnerMatcher, *Node, *Context)) !=nullptr; + return selectFirst<T>(InnerId, match(InnerMatcher, *Node, *Context)) != + nullptr; } private: std::string Id; @@ -4221,7 +4221,7 @@ public: // Use the original typed pointer to verify we can pass pointers to subtypes // to equalsNode. const T *TypedNode = cast<T>(Node); - return selectFirst<const T>( + return selectFirst<T>( "", match(stmt(hasParent( stmt(has(stmt(equalsNode(TypedNode)))).bind(""))), *Node, Context)) != nullptr; @@ -4230,7 +4230,7 @@ public: // Use the original typed pointer to verify we can pass pointers to subtypes // to equalsNode. const T *TypedNode = cast<T>(Node); - return selectFirst<const T>( + return selectFirst<T>( "", match(decl(hasParent( decl(has(decl(equalsNode(TypedNode)))).bind(""))), *Node, Context)) != nullptr; |

