]> granicus.if.org Git - clang/commitdiff
Make clang-format actually respect custom brace wrapping flags.
authorDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 04:06:10 +0000 (04:06 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 04:06:10 +0000 (04:06 +0000)
This fixes llvm.org/PR25073.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249519 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index e9a02a00a430299e50c8112f867d8053344772a8..6bfd9cb5ceca114001d6d3192726546ff32cc92b 100644 (file)
@@ -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:";
index ff9d2d473ffcb9dadc35c2c479f77882870da9c5..00f87ba951549efa9143fd501cfdc034d7270a56 100644 (file)
@@ -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) {