Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2244,18 +2244,26 @@ --Line->Level; if (LeftAlignLabel) Line->Level = 0; + + bool RemoveWhiteSmithCaseIndent = + (!Style.IndentCaseBlocks && + Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths); + + if (RemoveWhiteSmithCaseIndent) + --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 || RemoveWhiteSmithCaseIndent); 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 (RemoveWhiteSmithCaseIndent) { 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(); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -13538,7 +13538,7 @@ " {\n" " switch (a)\n" " {\n" - " case 2:\n" + " case 2:\n" " {\n" " }\n" " break;\n" @@ -13550,18 +13550,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", @@ -13571,12 +13571,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"