From ac7e34e778e84ed4105d098811f67a9646549059 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 13 Mar 2014 10:11:17 +0000 Subject: [PATCH] clang-format: Prevent ObjC code from confusing the braced-init detection This was leading to bad formatting, e.g.: Before: f(^{ @autoreleasepool { if (a) { g(); } } }); After: f(^{ @autoreleasepool { if (a) { g(); } } }); llvm-svn: 203777 --- clang/lib/Format/UnwrappedLineParser.cpp | 1 + clang/unittests/Format/FormatTest.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index daf185be519e..a3087ed98454 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -357,6 +357,7 @@ void UnwrappedLineParser::calculateBraceTypes() { LBraceStack.pop_back(); } break; + case tok::at: case tok::semi: case tok::kw_if: case tok::kw_while: diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 44e8bf849d38..5d4c1172c136 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8062,6 +8062,14 @@ TEST_F(FormatTest, FormatsBlocks) { " // ...\n" " int i;\n" " }];"); + + verifyFormat("f(^{\n" + " @autoreleasepool {\n" + " if (a) {\n" + " g();\n" + " }\n" + " }\n" + "});"); } TEST_F(FormatTest, SupportsCRLF) {