D26943: [CodingStandards] Add style guide rule about "if" statements and loops.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 23 00:22:10 PST 2016


On Tue, Nov 22, 2016 at 8:22 AM, Robinson, Paul via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
>
> > -----Original Message-----
> > From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On
> Behalf
> > Of Robinson, Paul via llvm-commits
> > Sent: Tuesday, November 22, 2016 6:39 AM
> > To: reviews+D26943+public+5c1a379143b6f3e8 at reviews.llvm.org; Matt
> > Arsenault; jlebar at google.com; rnk at google.com; matze at braunis.de
> > Cc: llvm-commits at lists.llvm.org
> > Subject: RE: D26943: [CodingStandards] Add style guide rule about "if"
> > statements and loops.
> >
> >
> >
> > > -----Original Message-----
> > > From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On
> > Behalf
> > > Of Matt Arsenault via llvm-commits
> > > Sent: Monday, November 21, 2016 4:02 PM
> > > To: jlebar at google.com; rnk at google.com; matze at braunis.de
> > > Cc: llvm-commits at lists.llvm.org
> > > Subject: [PATCH] D26943: [CodingStandards] Add style guide rule about
> > "if"
> > > statements and loops.
> > >
> > > arsenm added a comment.
> > >
> > > In https://reviews.llvm.org/D26943#601970, @MatzeB wrote:
> > >
> > > > In https://reviews.llvm.org/D26943#601961, @compnerd wrote:
> > > >
> > > > > Personally, I think I would prefer that we add braces only if one
> of
> > > the bodies of the code path requires it:
> > > >
> > > >
> > > > Just for the sake of discussion (I personally would prefer braces).
> > This
> > > would result in this in the extreme case:
> > > >
> > > >   if (foo)
> > > >     for (Baz b : bazes)
> > > >       if (b)
> > > >         ++BCount;
> > > >       else
> > > >         ++NotBCount;
> > > >   else
> > > >     foobar();
> > > >
> > >
> > >
> > > +1 for braces
> >
> > +1.  In this example both the outermost 'if' and the 'for' have
> > a multiline body (even if each individual statement has only 1 line)
> > and so I also prefer they have braces.
>
> 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.

My 2cents.

-- Sean Silva



>
> > --paulr
> >
> > >
> > >
> > > https://reviews.llvm.org/D26943
> > >
> > >
> > >
> > > _______________________________________________
> > > llvm-commits mailing list
> > > llvm-commits at lists.llvm.org
> > > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161123/31352b92/attachment.html>


More information about the llvm-commits mailing list