From 395193c7a0cd1366e33c1bd23590eb6ea06f5251 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 28 Mar 2014 07:48:59 +0000 Subject: [PATCH] clang-format: Recognize more ObjC blocks with parameters/return type. llvm-svn: 204990 --- clang/lib/Format/UnwrappedLineParser.cpp | 8 ++++++-- clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index d863b5db0c05..204132daae39 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -694,9 +694,13 @@ void UnwrappedLineParser::parseStructuralElement() { break; case tok::caret: nextToken(); - if (FormatTok->is(tok::l_brace)) { + if (FormatTok->Tok.isAnyIdentifier() || + FormatTok->isSimpleTypeSpecifier()) + nextToken(); + if (FormatTok->is(tok::l_paren)) + parseParens(); + if (FormatTok->is(tok::l_brace)) parseChildBlock(); - } break; case tok::l_brace: if (!tryToParseBracedList()) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 3d1e5a5d8e27..2bf55125765f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8125,6 +8125,10 @@ TEST_F(FormatTest, FormatsLambdas) { TEST_F(FormatTest, FormatsBlocks) { verifyFormat("int (^Block)(int, int);"); verifyFormat("int (^Block1)(int, int) = ^(int i, int j)"); + verifyFormat("void (^block)(int) = ^(id test) { int i; };"); + verifyFormat("void (^block)(int) = ^(int test) { int i; };"); + verifyFormat("void (^block)(int) = ^id(int test) { int i; };"); + verifyFormat("void (^block)(int) = ^int(int test) { int i; };"); verifyFormat("foo(^{ bar(); });"); verifyFormat("foo(a, ^{ bar(); });");