[PATCH] D26943: [CodingStandards] Add style guide rule about "if" statements and loops.
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 23 09:00:10 PST 2016
rnk added a comment.
>> Although, for really simple cases it's probably fine to omit them:
>>
>> if (auto Foo = bar())
>> for (auto Baz : Foo.stuff())
>> bazIt(Baz);
>
> These types of constructs are one of my favorite parts of idiomatic LLVM code. I'd hate to lose them.
I'm sympathetic to this idiom, but I can't come up with an easy way to write a rule to allow it:
for (Foo *f : foos)
if (f->isSomething())
return true;
return false;
I also don't like it when it gets to three blocks.
for (Foo *f : foos)
if (auto *b = dyn_cast<Bar>(f->getBar()))
if (b->isBaz())
return true;
return false;
It's too clever.
I'd rather have an easy rule of thumb that requires this:
for (Foo *f : foos) {
if (f->isSomething())
return true;
}
return false;
I've also seen this before, and I want to make sure I don't see it again:
for (Foo *f : foos)
if (f->isSomething()) {
stmt1();
stmt2();
}
https://reviews.llvm.org/D26943
More information about the llvm-commits
mailing list