Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1245,7 +1245,8 @@ // If in Whitemsmiths mode, indent start and end of blocks if (Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths) { - if (RootToken.isOneOf(tok::l_brace, tok::r_brace, tok::kw_case)) + if (RootToken.isOneOf(tok::l_brace, tok::r_brace, tok::kw_case, + tok::kw_default)) Indent += Style.IndentWidth; } Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2214,8 +2214,13 @@ parseBlock(/*MustBeDeclaration=*/false); if (FormatTok->Tok.is(tok::kw_break)) { if (Style.BraceWrapping.AfterControlStatement == - FormatStyle::BWACS_Always) + FormatStyle::BWACS_Always) { addUnwrappedLine(); + if (!Style.IndentCaseBlocks && + Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths) { + Line->Level++; + } + } parseStructuralElement(); } addUnwrappedLine(); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12941,9 +12941,7 @@ " }\n", WhitesmithsBraceStyle); - // FIXME: the block and the break under case 2 in this test don't get indented - // correctly - /* + WhitesmithsBraceStyle.IndentCaseBlocks = true; verifyFormat("void switchTest1(int a)\n" " {\n" " switch (a)\n" @@ -12951,35 +12949,101 @@ " case 2:\n" " {\n" " }\n" - " break;\n" + " break;\n" " }\n" " }\n", WhitesmithsBraceStyle); - */ - // FIXME: the block and the break under case 2 in this test don't get indented - // correctly - /* verifyFormat("void switchTest2(int a)\n" " {\n" " switch (a)\n" " {\n" - " case 0:\n" + " case 0:\n" " break;\n" - " case 1:\n" + " case 1:\n" + " {\n" + " break;\n" + " }\n" + " case 2:\n" + " {\n" + " }\n" + " break;\n" + " default:\n" + " break;\n" + " }\n" + " }\n", + WhitesmithsBraceStyle); + + verifyFormat("void switchTest3(int a)\n" + " {\n" + " switch (a)\n" " {\n" + " case 0:\n" + " {\n" + " foo(x);\n" + " }\n" + " break;\n" + " default:\n" + " {\n" + " foo(1);\n" + " }\n" " break;\n" " }\n" - " case 2:\n" + " }\n", + WhitesmithsBraceStyle); + + WhitesmithsBraceStyle.IndentCaseBlocks = false; + + verifyFormat("void switchTest4(int a)\n" + " {\n" + " switch (a)\n" + " {\n" + " case 2:\n" " {\n" " }\n" " break;\n" - " default:\n" + " }\n" + " }\n", + WhitesmithsBraceStyle); + + verifyFormat("void switchTest5(int a)\n" + " {\n" + " switch (a)\n" + " {\n" + " case 0:\n" + " break;\n" + " case 1:\n" + " {\n" + " foo();\n" + " break;\n" + " }\n" + " case 2:\n" + " {\n" + " }\n" + " break;\n" + " default:\n" + " break;\n" + " }\n" + " }\n", + WhitesmithsBraceStyle); + + verifyFormat("void switchTest6(int a)\n" + " {\n" + " switch (a)\n" + " {\n" + " case 0:\n" + " {\n" + " foo(x);\n" + " }\n" + " break;\n" + " default:\n" + " {\n" + " foo(1);\n" + " }\n" " break;\n" " }\n" " }\n", WhitesmithsBraceStyle); - */ verifyFormat("enum X\n" " {\n"