Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit e64d34c

Browse files
committed
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
1 parent 8dc6883 commit e64d34c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Diff for: lib/Format/FormatToken.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,12 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
218218
ItemBegin = ItemEnd->Next;
219219
}
220220

221-
// Don't use column layout for nested lists, lists with few elements and in
222-
// presence of separating comments.
223-
if ((Token->NestingLevel != 0 && Token->is(tok::l_brace)) ||
224-
Commas.size() < 5 || HasSeparatingComment)
221+
// Don't use column layout for lists with few elements and in presence of
222+
// separating comments.
223+
if (Commas.size() < 5 || HasSeparatingComment)
224+
return;
225+
226+
if (Token->NestingLevel != 0 && Token->is(tok::l_brace) && Commas.size() < 19)
225227
return;
226228

227229
// We can never place more than ColumnLimit / 3 items in a row (because of the

Diff for: unittests/Format/FormatTest.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -6544,6 +6544,15 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
65446544
" struct Dummy {};\n"
65456545
" f(v);\n"
65466546
"}");
6547+
6548+
// Long lists should be formatted in columns even if they are nested.
6549+
verifyFormat(
6550+
"vector<int> x = function({1, 22, 333, 4444, 55555, 666666, 7777777,\n"
6551+
" 1, 22, 333, 4444, 55555, 666666, 7777777,\n"
6552+
" 1, 22, 333, 4444, 55555, 666666, 7777777,\n"
6553+
" 1, 22, 333, 4444, 55555, 666666, 7777777,\n"
6554+
" 1, 22, 333, 4444, 55555, 666666, 7777777,\n"
6555+
" 1, 22, 333, 4444, 55555, 666666, 7777777});");
65476556
}
65486557

65496558
TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {

0 commit comments

Comments
 (0)