]> granicus.if.org Git - clang/commitdiff
clang-format: Align long braced init lists even if they are nested in
authorDaniel Jasper <djasper@google.com>
Mon, 4 Jan 2016 07:30:44 +0000 (07:30 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 4 Jan 2016 07:30:44 +0000 (07:30 +0000)
function calls.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256740 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/FormatToken.cpp
unittests/Format/FormatTest.cpp

index 63af0d6088d17fb175affa6c9de03f24b4234d4b..d6cd450d892e72b9c03deeb4f29d207bdb08c81a 100644 (file)
@@ -218,10 +218,12 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
     ItemBegin = ItemEnd->Next;
   }
 
-  // Don't use column layout for nested lists, lists with few elements and in
-  // presence of separating comments.
-  if ((Token->NestingLevel != 0 && Token->is(tok::l_brace)) ||
-      Commas.size() < 5 || HasSeparatingComment)
+  // Don't use column layout for lists with few elements and in presence of
+  // separating comments.
+  if (Commas.size() < 5 || HasSeparatingComment)
+    return;
+
+  if (Token->NestingLevel != 0 && Token->is(tok::l_brace) && Commas.size() < 19)
     return;
 
   // We can never place more than ColumnLimit / 3 items in a row (because of the
index 5c5c986a2ccd9c655cfb969897c6f0d2134869a2..259a9961a5e2967a3258555b965f0f30c49705d0 100644 (file)
@@ -6544,6 +6544,15 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
                "  struct Dummy {};\n"
                "  f(v);\n"
                "}");
+
+  // Long lists should be formatted in columns even if they are nested.
+  verifyFormat(
+      "vector<int> x = function({1, 22, 333, 4444, 55555, 666666, 7777777,\n"
+      "                          1, 22, 333, 4444, 55555, 666666, 7777777,\n"
+      "                          1, 22, 333, 4444, 55555, 666666, 7777777,\n"
+      "                          1, 22, 333, 4444, 55555, 666666, 7777777,\n"
+      "                          1, 22, 333, 4444, 55555, 666666, 7777777,\n"
+      "                          1, 22, 333, 4444, 55555, 666666, 7777777});");
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {