[PATCH] D94031: [ASTMatchers] Fix child traversal over range-for loops
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 5 12:29:20 PST 2021
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.
LGTM!
================
Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:245
+ ScopedIncrement ScopedDepth(&CurrentDepth);
+ if (!match(*Node->getLoopVariable()) || !match(*Node->getRangeInit()) ||
+ !match(*Node->getBody()))
----------------
steveire wrote:
> aaron.ballman wrote:
> > steveire wrote:
> > > aaron.ballman wrote:
> > > > Should we be traversing the init statement before the loop variable so that the traversals happen in lexical order?
> > > Do you mean that in
> > >
> > > ```
> > > for (auto i : arr)
> > > {
> > > }
> > > ```
> > >
> > > to visit the `arr` before the `auto i`?
> > >
> > > I think visiting the `auto i` before the `arr` makes sense.
> > Nope, I mean that in:
> > ```
> > for (int i = 12; auto j : {1, 2, 3, 4}) {}
> > ```
> > we should visit the `int i = 12;` before the `auto j`
> That was actually missing entirely. Added now.
I thought `getRangeInit()` was doing that already, so nice!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94031/new/
https://reviews.llvm.org/D94031
More information about the cfe-commits
mailing list