From 79ad0bf228efc7219fa0baa811cb46e4c0184f44 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Wed, 2 Dec 2020 20:07:13 -0800 Subject: [PATCH] Make the rules for braces on `if`s and loops simpler and more strict. (#194) This simply requires braces and doesn't allow single-line `if`s. There is some minor readability loss here, but it seems minor and provides extremely simple rules which I'd value. I can also trivially get clang-tidy to both check for this and automatically fix code to conform. Just sending this as a code review as it seems fully in the direction of the style guide approved by the core team and I've heard no real objections. That said, if anyone is concerned, I'm happy to take it through the proposal process. --- docs/project/cpp_style_guide.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/project/cpp_style_guide.md b/docs/project/cpp_style_guide.md index df3d5ffe3b74..7ea3328e036d 100644 --- a/docs/project/cpp_style_guide.md +++ b/docs/project/cpp_style_guide.md @@ -121,8 +121,12 @@ these. - Use `{}` initialization without the `=` only if the above options don't compile. - Never mix `{}` initialization and `auto`. -- Don't put both the `if`-condition and subsequent statement onto a single - line. +- Always use braces for conditional, `switch`, and loop statements, even when + the body is a single statement. + - Within a `switch` statement, use braces after a `case` label when + necessary to create a scope for a variable. + - Always break the line immediately after an open brace except for empty + loop bodies. ### Copyable and movable types