Author: djasper Date: Mon Jan 4 01:30:44 2016 New Revision: 256740 URL: http://llvm.org/viewvc/llvm-project?rev=256740&view=rev Log: clang-format: Align long braced init lists even if they are nested in function calls.
Modified: cfe/trunk/lib/Format/FormatToken.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/FormatToken.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=256740&r1=256739&r2=256740&view=diff ============================================================================== --- cfe/trunk/lib/Format/FormatToken.cpp (original) +++ cfe/trunk/lib/Format/FormatToken.cpp Mon Jan 4 01:30:44 2016 @@ -218,10 +218,12 @@ void CommaSeparatedList::precomputeForma 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 Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=256740&r1=256739&r2=256740&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 4 01:30:44 2016 @@ -6544,6 +6544,15 @@ TEST_F(FormatTest, FormatsBracedListsInC " 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits