Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1798,12 +1798,18 @@ break; case tok::caret: nextToken(); + // Block return type. if (FormatTok->Tok.isAnyIdentifier() || FormatTok->isSimpleTypeSpecifier()) { nextToken(); + // Return types: pointers are ok too. + while (FormatTok->is(tok::star)) + nextToken(); } + // Block argument list. if (FormatTok->is(tok::l_paren)) parseParens(); + // Block body. if (FormatTok->is(tok::l_brace)) parseChildBlock(); break; Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -22619,7 +22619,8 @@ " }\n" " }\n" "});"); - verifyFormat("Block b = ^int *(A *a, B *b) {}"); + verifyFormat("Block b = ^int *(A *a, B *b) {\n" + "};"); verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n" "};"); Index: clang/unittests/Format/FormatTestObjC.cpp =================================================================== --- clang/unittests/Format/FormatTestObjC.cpp +++ clang/unittests/Format/FormatTestObjC.cpp @@ -1019,6 +1019,20 @@ verifyFormat("int (^foo[kNumEntries])(char, float);"); verifyFormat("int (^foo[kNumEntries + 10])(char, float);"); verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);"); + + verifyFormat("int *p = ^int *() { //\n" + " return nullptr;\n" + "}();"); + + verifyFormat("int * (^p)(void) = ^int *(void) { //\n" + " return nullptr;\n" + "};"); + + // WebKit forces function braces onto a newline, but blocks should not. + verifyFormat("int* p = ^int*() { //\n" + " return nullptr;\n" + "}();", + getWebKitStyle()); } TEST_F(FormatTestObjC, ObjCSnippets) {