Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -142,8 +142,20 @@ bool StartsObjCMethodExpr = false; if (CurrentToken->is(tok::caret)) { - // (^ can start a block type. - Left->Type = TT_ObjCBlockLParen; + const FormatToken *Next = CurrentToken->getNextNonComment(); + if (Next && + // int (^)(char, float) + (Next->startsSequence(tok::r_paren, tok::l_paren) || + // int (^blockReturningIntWithCharAndFloatArguments)(char, float) + Next->startsSequence(tok::identifier, tok::r_paren, tok::l_paren) || + // int + // (^arrayOfTenBlocksReturningIntWithCharAndFloatArguments[10])(char, + // float) + Next->startsSequence(tok::identifier, tok::l_square, + tok::numeric_constant, tok::r_square, + tok::r_paren, tok::l_paren))) { + Left->Type = TT_ObjCBlockLParen; + } } else if (FormatToken *MaybeSel = Left->Previous) { // @selector( starts a selector. if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous && Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -12024,6 +12024,16 @@ "for (const Foo& baz = in.value(); !baz.at_end(); ++baz) {}")); } +TEST_F(FormatTest, GuessLanguageWithCaret) { + EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);")); + EXPECT_EQ(FormatStyle::LK_ObjC, + guessLanguage("foo.h", "int(^)(char, float);")); + EXPECT_EQ(FormatStyle::LK_ObjC, + guessLanguage("foo.h", "int(^foo)(char, float);")); + EXPECT_EQ(FormatStyle::LK_ObjC, + guessLanguage("foo.h", "int(^foo[10])(char, float);")); +} + } // end namespace } // end namespace format } // end namespace clang