[llvm-dev] Codifying our Brace rules-

Adrian McCarthy via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 15 14:52:33 PDT 2020


I personally prefer always including the braces, but, of course, I'll abide
by the local style rules.  That said, is the local style rule implemented
in clang-format?  I've never noticed it removing nor adding syntactically
unnecessary braces.

A few times, I've had a bit of a panic attack on code of this form:

if (condition)
  // there's a comment here
  Statement = Something;
else
  ComputeThisOrThat();


It's correct, but it looks like it's not, especially when it's nested
within a clause of another "outer" if statement.

On Mon, Jun 15, 2020 at 2:35 PM David Greene via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Matt Arsenault via llvm-dev <llvm-dev at lists.llvm.org> writes:
>
> > I think braces should be added in all contexts, and the more contexts
> > the better. It eliminates any inconsistency or attempt to contextually
> > interpret rules. It also reduces merge conflicts, since something
> > eventually something will probably be added inside any control flow
> > statement. I’ve suffered through many painful merges trying to find
> > where the braces went wrong, usually due to switch statements. The
> > sometimes-braces-sometimes-not combined with the lack of indentation
> > for switch cases leads to way more time figuring out braces than
> > should be necessary.
>
> +1.  In addition, the lack of braces can lead to subtle bugs if one adds
> a line to an existing single-line conditional statement.  Best to be
> safe and always use braces.
>
>                 -David
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200615/54a4fd4b/attachment.html>


More information about the llvm-dev mailing list