diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2244,18 +2244,26 @@ --Line->Level; if (LeftAlignLabel) Line->Level = 0; + + bool RemoveWhitesmithsCaseIndent = + (!Style.IndentCaseBlocks && + Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths); + + if (RemoveWhitesmithsCaseIndent) + --Line->Level; + if (!Style.IndentCaseBlocks && CommentsBeforeNextToken.empty() && FormatTok->Tok.is(tok::l_brace)) { - CompoundStatementIndenter Indenter(this, Line->Level, - Style.BraceWrapping.AfterCaseLabel, - Style.BraceWrapping.IndentBraces); + + CompoundStatementIndenter Indenter( + this, Line->Level, Style.BraceWrapping.AfterCaseLabel, + Style.BraceWrapping.IndentBraces || RemoveWhitesmithsCaseIndent); parseBlock(/*MustBeDeclaration=*/false); if (FormatTok->Tok.is(tok::kw_break)) { if (Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_Always) { addUnwrappedLine(); - if (!Style.IndentCaseBlocks && - Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths) { + if (RemoveWhitesmithsCaseIndent) { Line->Level++; } } @@ -2276,6 +2284,7 @@ void UnwrappedLineParser::parseCaseLabel() { assert(FormatTok->Tok.is(tok::kw_case) && "'case' expected"); + // FIXME: fix handling of complex expressions here. do { nextToken(); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -13658,7 +13658,7 @@ " {\n" " switch (a)\n" " {\n" - " case 2:\n" + " case 2:\n" " {\n" " }\n" " break;\n" @@ -13670,18 +13670,18 @@ " {\n" " switch (a)\n" " {\n" - " case 0:\n" + " case 0:\n" " break;\n" - " case 1:\n" + " case 1:\n" " {\n" " foo();\n" " break;\n" " }\n" - " case 2:\n" + " case 2:\n" " {\n" " }\n" " break;\n" - " default:\n" + " default:\n" " break;\n" " }\n" " }\n", @@ -13691,12 +13691,12 @@ " {\n" " switch (a)\n" " {\n" - " case 0:\n" + " case 0:\n" " {\n" " foo(x);\n" " }\n" " break;\n" - " default:\n" + " default:\n" " {\n" " foo(1);\n" " }\n"