summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-05-22 13:53:55 +0000
committerDaniel Jasper <djasper@google.com>2014-05-22 13:53:55 +0000
commit565ed5ed08fda3af5d26d6f0a47f4bb36d3e8b57 (patch)
tree950cf368c48583baddf4f0b25ddeed96a0cb27d2
parent498e56adb6c05d69afc300eeadce12fadfc3e477 (diff)
downloadbcm5719-llvm-565ed5ed08fda3af5d26d6f0a47f4bb36d3e8b57.tar.gz
bcm5719-llvm-565ed5ed08fda3af5d26d6f0a47f4bb36d3e8b57.zip
clang-format: Don't use Allman brace breaking for ObjC blocks.
It just seems wrong. This fixes llvm.org/PR19736. llvm-svn: 209440
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp3
-rw-r--r--clang/unittests/Format/FormatTest.cpp10
2 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ce847d6427e..f057ef7f3e7 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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) &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b3fb776a7a6..9cf4efcbf1f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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;
OpenPOWER on IntegriCloud