Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1785,7 +1785,11 @@ if (FormatTok->Tok.is(tok::kw_else)) { nextToken(); if (FormatTok->Tok.is(tok::l_brace)) { - CompoundStatementIndenter Indenter(this, Style, Line->Level); + CompoundStatementIndenter Indenter( + this, Line->Level, + Style.BraceWrapping.AfterControlStatement == + FormatStyle::BWACS_Always, + Style.BraceWrapping.IndentBraces); parseBlock(/*MustBeDeclaration=*/false); addUnwrappedLine(); } else if (FormatTok->Tok.is(tok::kw_if)) { @@ -1823,7 +1827,10 @@ parseParens(); } if (FormatTok->is(tok::l_brace)) { - CompoundStatementIndenter Indenter(this, Style, Line->Level); + CompoundStatementIndenter Indenter( + this, Line->Level, + Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_Always, + Style.BraceWrapping.IndentBraces); parseBlock(/*MustBeDeclaration=*/false); if (Style.BraceWrapping.BeforeCatch) { addUnwrappedLine(); @@ -1861,7 +1868,10 @@ nextToken(); } NeedsUnwrappedLine = false; - CompoundStatementIndenter Indenter(this, Style, Line->Level); + CompoundStatementIndenter Indenter( + this, Line->Level, + Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_Always, + Style.BraceWrapping.IndentBraces); parseBlock(/*MustBeDeclaration=*/false); if (Style.BraceWrapping.BeforeCatch) addUnwrappedLine(); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -1565,6 +1565,41 @@ " baz();\n" "}", format("try{foo();}catch(Exception&bar){baz();}", Style)); + Style.ColumnLimit = + 40; // to concentrate at brace wrapping, not line wrap due to column limit + EXPECT_EQ("try {\n" + " foo();\n" + "} catch (Exception &bar) {\n" + " baz();\n" + "}", + format("try{foo();}catch(Exception&bar){baz();}", Style)); + Style.ColumnLimit = + 20; // to concentrate at brace wrapping, not line wrap due to column limit + + Style.BraceWrapping.BeforeElse = true; + EXPECT_EQ( + "if (foo) {\n" + " bar();\n" + "}\n" + "else if (baz ||\n" + " quux)\n" + "{\n" + " foobar();\n" + "}\n" + "else {\n" + " barbaz();\n" + "}", + format("if(foo){bar();}else if(baz||quux){foobar();}else{barbaz();}", + Style)); + + Style.BraceWrapping.BeforeCatch = true; + EXPECT_EQ("try {\n" + " foo();\n" + "}\n" + "catch (...) {\n" + " baz();\n" + "}", + format("try{foo();}catch(...){baz();}", Style)); } //===----------------------------------------------------------------------===// @@ -14881,7 +14916,7 @@ verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle); } - TEST_F(FormatTest, SpacesInConditionalStatement) { +TEST_F(FormatTest, SpacesInConditionalStatement) { FormatStyle Spaces = getLLVMStyle(); Spaces.SpacesInConditionalStatement = true; verifyFormat("for ( int i = 0; i; i++ )\n continue;", Spaces);