[PATCH] D80947: Add to the Coding Standard our that single-line bodies omit braces

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 3 07:06:09 PDT 2020


erichkeane marked 5 inline comments as done.
erichkeane added inline comments.


================
Comment at: llvm/docs/CodingStandards.rst:1573
 
+Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
----------------
arsenm wrote:
> I would rather just ban single line statements like this and require putting them on the next line.
> 
> For the case of cases, especially when combined with the style of not indenting the cases from the switch, omitting braces is really painful. So many times I've produced bad merges and had a hard time figuring out where the double }} at the end is necessary. It would be easier to just always use the braces
It is not my intent in this patch to actually change our coding standard, simply to codify the rule that we've been enforcing for a decade.


================
Comment at: llvm/docs/CodingStandards.rst:1603
+
+  // This should also omit braces.  The for loop contains only a single statement,
+  // so it shouldn't have braces.  The if also only contains a single statement (the
----------------
arsenm wrote:
> This loop should use braces. It covers multiple lines. Omitting braces invariably just increases diffs/merge conflicts when something else is added to the loop body.
> 
> This one isn't consistently applied and I've been enforcing the opposite
This is how we've been enforcing the rule however, can you suggest a change to the wording that you think would match our current enforcement?


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

https://reviews.llvm.org/D80947





More information about the cfe-commits mailing list