From: Daniel Jasper Date: Mon, 26 Sep 2016 22:19:08 +0000 (+0000) Subject: [clang-format] Don't allow newline after uppercase Obj-C block return types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=199dbc55ee14d177b12436c7058c75ffdd25da1c;p=clang [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! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282448 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 72d869782c..428a068889 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index bac2a5b7a9..06a7e7ee91 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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;