[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
Mon Jun 15 12:41:59 PDT 2020


erichkeane marked an inline comment as done.
erichkeane added inline comments.


================
Comment at: llvm/docs/CodingStandards.rst:1600
+  // Omit the braces, since the body is simple and clearly associated with the if.
+  if (isa<FunctionDecl>(D))
+    handleFunctionDecl(D);
----------------
smeenai wrote:
> I'm late to the party here (and I haven't read the entirety of the previous discussion, sorry), but I thought our rule had always been "if one arm of an if/else requires braces, put braces on all of them". In other words, the `if` and `else if` here should have braces, since the `else` does.
I believe this then has been particularly poorly enforced then.  Since the rule was unwritten, its enforcement across the codebase has been extremely inconsistent. 

For example, Clang has a number of if/else-if/else chains where braces are omitted JUST in the middle!

I would love for us (the community) to have a discussion to determine what the rule ACTUALLY is, but am not sure this part has been uniformly enforced sufficiently enough to put it in the text without discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80947





More information about the cfe-commits mailing list