]> granicus.if.org Git - clang/commitdiff
clang-format: Fixed typecast getting put on a separate line from the
authorDaniel Jasper <djasper@google.com>
Mon, 12 Oct 2015 03:19:07 +0000 (03:19 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 12 Oct 2015 03:19:07 +0000 (03:19 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index bcd50a88bcd30d887f05595d508e51f19d9b94e8..fc89d2bafff9560c22bdcfaabcb8cac0fb9148bc 100644 (file)
@@ -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;
index 3cf181ed484fa900e1f3d1d4eb91b88682f24dac..06970bac0a0ff6e8b36e350f02d1db73bd823f2a 100644 (file)
@@ -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) {