[PATCH] D43183: clang-format: introduce `CaseBlockIndent` to control indent in switch

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 13 05:11:02 PST 2018


Typz added a comment.

> Do you have a reference to style guides recommending any of this?

Unfortunately not... I think this is a really advanced topic, and often not recommended way to format code at all (e.g. "if you need a block, you may as well use a function"). I can find the current implementation documented in google style guide, where there is an extra indent inside switch [e.g. `IndentCaseLabels`], which alleviates the ambiguity. But it is not documented (or shown) in the LLVM coding style, where it makes the code IMO really difficult to follow.

I believe the 2 extra modes I introduce should provide for most cases, leaving the decision to user:

- `None` mode matches google-style, and is perfectly fine when `IndentCaseLabels == true`
- `ClosingBrace` mode is "logical" with what people may want (e.g. have a scope for the whole `case` block), but is not syntaxically correct and may thus mislead
- `Block` mode is syntaxically correct, but somewhat breaks the switch layout by moving break to different indentation levels depending on the use of braces

Which mode is use is then left to the user, depending on the "goals" of their coding style.

Also, maybe this is a small-enough detail that it would be better moved to the `BraceWrapping` field, to allow finely tuning the expected behavior (e.g. in Custom brace mode) while keeping the 'main' options simple (even though it is not technically a way to wrap the braces).


Repository:
  rC Clang

https://reviews.llvm.org/D43183





More information about the cfe-commits mailing list