mattd added inline comments.
================ Comment at: lib/Sema/SemaStmt.cpp:2346 + // Assume the variables are nested in the inner scope (loop body). + const auto DepthStr = std::to_string(S->getDepth() >> 1); VarDecl *BeginVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType, ---------------- dblaikie wrote: > Why shifted right/divided by two? (I'd probably write this as "/ 2" rather > thane ">> 1" if this is what's) > > I guess this is because a range-for introduces two (actually 3, I think) > scopes? > > But what about if there are other random scopes that could be present? Does > that adversely affect anything here? Thanks for the comment. Honestly, I discovered the pattern after crafting up a tightly nested loop example, and realized that my Depths were 2,4,6... for each range loop respectively. I think it's two scopes and the range variables (__begin, __end, __range) are nestled inside each inner scope. Thus each range loop seems to be created of 2 scopes. If there are other scopes between two range-loops, such as the 'if' in the example below, then the outer-most "for" is range1/begin1/end1, followed by the middle loop: range3/begin3/end3, and the innermost: range4/begin4/end4. ``` for (...) // range1 if (...) for(...) // range 3 for (...) //range4 ``` https://reviews.llvm.org/D42813 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits