Author: djasper Date: Mon Sep 26 17:19:08 2016 New Revision: 282448 URL: http://llvm.org/viewvc/llvm-project?rev=282448&view=rev Log: [clang-format] Don't allow newline after uppercase Obj-C block return types
Fixes the following: BOOL (^aaa)(void) = ^BOOL { }; The first BOOL's token was getting set to TT_FunctionAnnotationRParen incorrectly, which was causing an unexpected newline after (^aaa). This was introduced in r245846. Patch by Kent Sutherland, thank you! Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=282448&r1=282447&r2=282448&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Sep 26 17:19:08 2016 @@ -1037,12 +1037,17 @@ private: !Current.Next->isBinaryOperator() && !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace, tok::period, tok::arrow, tok::coloncolon)) - if (FormatToken *BeforeParen = Current.MatchingParen->Previous) - if (BeforeParen->is(tok::identifier) && - BeforeParen->TokenText == BeforeParen->TokenText.upper() && - (!BeforeParen->Previous || - BeforeParen->Previous->ClosesTemplateDeclaration)) - Current.Type = TT_FunctionAnnotationRParen; + if (FormatToken *AfterParen = Current.MatchingParen->Next) { + // Make sure this isn't the return type of an Obj-C block declaration + if (AfterParen->Tok.isNot(tok::caret)) { + if (FormatToken *BeforeParen = Current.MatchingParen->Previous) + if (BeforeParen->is(tok::identifier) && + BeforeParen->TokenText == BeforeParen->TokenText.upper() && + (!BeforeParen->Previous || + BeforeParen->Previous->ClosesTemplateDeclaration)) + Current.Type = TT_FunctionAnnotationRParen; + } + } } else if (Current.is(tok::at) && Current.Next) { if (Current.Next->isStringLiteral()) { Current.Type = TT_ObjCStringLiteral; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=282448&r1=282447&r2=282448&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Sep 26 17:19:08 2016 @@ -11156,6 +11156,8 @@ TEST_F(FormatTest, FormatsBlocks) { " }\n" "});"); verifyFormat("Block b = ^int *(A *a, B *b) {}"); + verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n" + "};"); FormatStyle FourIndent = getLLVMStyle(); FourIndent.ObjCBlockIndentWidth = 4; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits