[PATCH] D126512: [Docs] Clarify the guideline on omitting braces

Owen Pan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 31 09:22:14 PDT 2022


owenpan added a comment.

In D126512#3547201 <https://reviews.llvm.org/D126512#3547201>, @erichkeane wrote:

> BUT THIS, for example:
>
>   if (isa<VarDecl>(D))
>      for (auto *A : D.attrs())
>        if (shouldProcessAttr(A))
>          handleAttr(A);
>
> Which I think the 'single line' rule you post breaks.  Also, my interpretation of what you wrote ALSo breaks 1649 in the 'after'.
>
> should remain the way.

It should not affect the examples you mentioned, but now I can see how it might be interpreted otherwise. I think removing the sentence "An ``if``/``else`` chain or a loop is considered
a single statement for this rule, and this rule applies recursively" would help. (See D126157 <https://reviews.llvm.org/D126157> for some examples it intends to clarify.)



================
Comment at: llvm/docs/CodingStandards.rst:1633
-      if (shouldProcessAttr(A))
-        handleAttr(A);
   }
----------------
mehdi_amini wrote:
> owenpan wrote:
> > mehdi_amini wrote:
> > > This example shows how this revision goes beyond do/while.
> > This example was very similar to the one starting at line 1662. After taking out one level of nesting here, it won't seem redundant to the "Use braces on the outer block because there are more than two levels of nesting" example below.
> I rather keep this example though if we don’t have a good reason to remove it
You would use the braces on the outer `if` in the original example **regardless** whether there was a potential dangling `else` situation because it had two levels of nesting. The revision removes the duplication. (In clang-format unit tests, this example doesn't really test the rule because of the multilevel nesting one below.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126512/new/

https://reviews.llvm.org/D126512



More information about the llvm-commits mailing list