From: Daniel Jasper Date: Mon, 12 Oct 2015 03:19:07 +0000 (+0000) Subject: clang-format: Fixed typecast getting put on a separate line from the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72c2907b9a6db3b8333b27eb021144d46b56b892;p=clang clang-format: Fixed typecast getting put on a separate line from the key in Obj-C dictionary literals This fixes: https://llvm.org/PR22647 Patch by Kent Sutherland. Thank you. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250010 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index bcd50a88bc..fc89d2baff 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -372,7 +372,9 @@ private: updateParameterCount(Left, CurrentToken); if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) { FormatToken *Previous = CurrentToken->getPreviousNonComment(); - if ((CurrentToken->is(tok::colon) || + if (((CurrentToken->is(tok::colon) && + (!Contexts.back().ColonIsDictLiteral || + Style.Language != FormatStyle::LK_Cpp)) || Style.Language == FormatStyle::LK_Proto) && Previous->Tok.getIdentifierInfo()) Previous->Type = TT_SelectorName; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3cf181ed48..06970bac0a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7531,6 +7531,13 @@ TEST_F(FormatTest, ObjCDictLiterals) { " bbbbbbbbbbbbbbbbbb : bbbbb,\n" " cccccccccccccccc : ccccccccccccccc\n" " }];"); + + // Ensure that casts before the key are kept on the same line as the key. + verifyFormat( + "NSDictionary *d = @{\n" + " (aaaaaaaa id)aaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaaaaaaaaaaaa,\n" + " (aaaaaaaa id)aaaaaaaaaaaaaa : (aaaaaaaa id)aaaaaaaaaaaaaa,\n" + "};"); } TEST_F(FormatTest, ObjCArrayLiterals) {