[PATCH] D43183: clang-format: introduce `CaseBlockIndent` to control indent in switch
Daniel Jasper via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 13 07:51:02 PST 2018
djasper added a comment.
In https://reviews.llvm.org/D43183#1006224, @Typz wrote:
> It is explicitly documented in google style guide: https://google.github.io/styleguide/cppguide.html#Loops_and_Switch_Statements :
>
> > case blocks in switch statements can have curly braces or not, depending on your preference. If you do include curly braces they should be placed as shown below.
> >
> > If not conditional on an enumerated value, switch statements should always have a default case (in the case of an enumerated value, the compiler will warn you if any values are not handled). If the default case should never execute, simply assert:
> >
> > switch (var) {
> > case 0: { // 2 space indent
> > ... // 4 space indent
> > break;
> > }
> > case 1: {
> > ...
> > break;
> > }
> > default: {
> > assert(false);
> > }
> > }
>
> So IMHO we cannot just change the current (or default) behaviour.
My proposal does not contradict this style guide as the case in question is not included in the example. It gives absolutely no guidance on how to format this case.
If anything, you could argue that it tells the user never to have something outside of the braces that make up a case statement (keep in mind that the style guide does not only give formatting advise).
Repository:
rC Clang
https://reviews.llvm.org/D43183
More information about the cfe-commits
mailing list