From: Daniel Jasper Date: Mon, 4 Jan 2016 07:30:44 +0000 (+0000) Subject: clang-format: Align long braced init lists even if they are nested in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e64d34cacffe012d5982287335cfe2338cb546d7;p=clang clang-format: Align long braced init lists even if they are nested in function calls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256740 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp index 63af0d6088..d6cd450d89 100644 --- a/lib/Format/FormatToken.cpp +++ b/lib/Format/FormatToken.cpp @@ -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 diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 5c5c986a2c..259a9961a5 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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 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) {