r209440 - clang-format: Don't use Allman brace breaking for ObjC blocks.

Daniel Jasper djasper at google.com
Thu May 22 06:53:55 PDT 2014


Author: djasper
Date: Thu May 22 08:53:55 2014
New Revision: 209440

URL: http://llvm.org/viewvc/llvm-project?rev=209440&view=rev
Log:
clang-format: Don't use Allman brace breaking for ObjC blocks.

It just seems wrong. This fixes llvm.org/PR19736.

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=209440&r1=209439&r2=209440&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu May 22 08:53:55 2014
@@ -1595,7 +1595,8 @@ bool TokenAnnotator::mustBreakBefore(con
              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) &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=209440&r1=209439&r2=209440&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 22 08:53:55 2014
@@ -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;





More information about the cfe-commits mailing list