[PATCH] D37264: [Docs] Update CodingStandards to recommend range-based for loops
Javed Absar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 29 10:13:01 PDT 2017
javed.absar added inline comments.
================
Comment at: docs/CodingStandards.rst:944
- for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II) {
- if (BinaryOperator *BO = dyn_cast<BinaryOperator>(II)) {
+ for (auto &I : BB) {
+ if (auto *BO = dyn_cast<BinaryOperator>(&I)) {
----------------
aaron.ballman wrote:
> majnemer wrote:
> > I'd replace the `auto` with `Instruction &`.
> We should clarify this in the coding standard, because I've always understood we generally *want* to use `auto` in range-based for loops, for brevity (and because the type is generally immediately apparent from the container).
In some complicated cases not using 'auto' improves code understanding. I have had cases where well established reviewers of llvm have recommended me not to use 'auto' in their review comment.
https://reviews.llvm.org/D37264
More information about the llvm-commits
mailing list