]> granicus.if.org Git - clang/commitdiff
clang-format: Don't use Allman brace breaking for ObjC blocks.
authorDaniel Jasper <djasper@google.com>
Thu, 22 May 2014 13:53:55 +0000 (13:53 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 22 May 2014 13:53:55 +0000 (13:53 +0000)
It just seems wrong. This fixes llvm.org/PR19736.

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

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

index ce847d6427e4bda6385dee3423fd2704191ba93f..f057ef7f3e740475471ae8ceacb77bc0659e7c04 100644 (file)
@@ -1595,7 +1595,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
              Style.BreakConstructorInitializersBeforeComma &&
              !Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {
     return true;
-  } else if (Right.is(tok::l_brace) && (Right.BlockKind == BK_Block)) {
+  } else if (Right.is(tok::l_brace) && Right.BlockKind == BK_Block &&
+             Right.Type != TT_ObjCBlockLBrace) {
     return Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
            Style.BreakBeforeBraces == FormatStyle::BS_GNU;
   } else if (Right.is(tok::string_literal) &&
index b3fb776a7a60669495268a5dffe893fd598333e7..9cf4efcbf1ff870fd1649356885242d698eda1dc 100644 (file)
@@ -7698,6 +7698,16 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
                "#endif",
                BreakBeforeBrace);
 
+  // This shouldn't affect ObjC blocks.
+  verifyFormat("[self doSomeThingWithACompletionHandler:^{\n"
+               "    // ...\n"
+               "    int i;\n"
+               "}];");
+  verifyFormat("void (^block)(void) = ^{\n"
+               "    // ...\n"
+               "    int i;\n"
+               "};");
+
   BreakBeforeBrace.ColumnLimit = 19;
   verifyFormat("void f() { int i; }", BreakBeforeBrace);
   BreakBeforeBrace.ColumnLimit = 18;