Make the rules for braces on ifs 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.
This commit is contained in:
Chandler Carruth
2020-12-02 20:07:13 -08:00
committed by GitHub
parent cc4211442f
commit 79ad0bf228
+6 -2
View File
@@ -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