From: Daniel Jasper Date: Wed, 7 Oct 2015 04:06:10 +0000 (+0000) Subject: Make clang-format actually respect custom brace wrapping flags. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a58694aec0bec92213e5b1bc70441dc5eba2007;p=clang Make clang-format actually respect custom brace wrapping flags. This fixes llvm.org/PR25073. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249519 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index e9a02a00a4..6bfd9cb5ce 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -372,6 +372,8 @@ std::string ParseErrorCategory::message(int EV) const { } static FormatStyle expandPresets(const FormatStyle &Style) { + if (Style.BreakBeforeBraces == FormatStyle::BS_Custom) + return Style; FormatStyle Expanded = Style; Expanded.BraceWrapping = {false, false, false, false, false, false, false, false, false, false, false}; @@ -442,6 +444,8 @@ FormatStyle getLLVMStyle() { LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None; LLVMStyle.BreakBeforeTernaryOperators = true; LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach; + LLVMStyle.BraceWrapping = {false, false, false, false, false, false, + false, false, false, false, false}; LLVMStyle.BreakConstructorInitializersBeforeComma = false; LLVMStyle.ColumnLimit = 80; LLVMStyle.CommentPragmas = "^ IWYU pragma:"; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ff9d2d473f..00f87ba951 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2332,8 +2332,8 @@ TEST_F(FormatTest, IncompleteTryCatchBlocks) { TEST_F(FormatTest, FormatTryCatchBraceStyles) { FormatStyle Style = getLLVMStyle(); - for (auto BraceStyle : - {FormatStyle::BS_Attach, FormatStyle::BS_Mozilla, FormatStyle::BS_WebKit}) { + for (auto BraceStyle : {FormatStyle::BS_Attach, FormatStyle::BS_Mozilla, + FormatStyle::BS_WebKit}) { Style.BreakBeforeBraces = BraceStyle; verifyFormat("try {\n" " // something\n" @@ -2384,6 +2384,15 @@ TEST_F(FormatTest, FormatTryCatchBraceStyles) { " // something\n" " }", Style); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.BeforeCatch = true; + verifyFormat("try {\n" + " // something\n" + "}\n" + "catch (...) {\n" + " // something\n" + "}", + Style); } TEST_F(FormatTest, FormatObjCTryCatch) {