summaryrefslogtreecommitdiffstats
path: root/lib/Format/FormatToken.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-05-15 09:41:59 +0000
committerDaniel Jasper <djasper@google.com>2015-05-15 09:41:59 +0000
commitb5236493da4bf9ba91101ffabb26c11ff38c3950 (patch)
treec331d1e72159afe9a78f9d9e8e1e592738fc3389 /lib/Format/FormatToken.cpp
parentb6c4df3a3217771fba1d8a05ae7336b7da056378 (diff)
clang-format: Don't use column layout in lists that have separating
comments. At some point, we might to want to a layout with a different number of columns instead, but at the moment, this causes more confusion than it's worth. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237427 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/FormatToken.cpp')
-rw-r--r--lib/Format/FormatToken.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp
index 2f0b32971b..42036666b0 100644
--- a/lib/Format/FormatToken.cpp
+++ b/lib/Format/FormatToken.cpp
@@ -153,10 +153,13 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
// trailing comments which are otherwise ignored for column alignment.
SmallVector<unsigned, 8> EndOfLineItemLength;
+ bool HasSeparatingComment = false;
for (unsigned i = 0, e = Commas.size() + 1; i != e; ++i) {
// Skip comments on their own line.
- while (ItemBegin->HasUnescapedNewline && ItemBegin->isTrailingComment())
+ while (ItemBegin->HasUnescapedNewline && ItemBegin->isTrailingComment()) {
ItemBegin = ItemBegin->Next;
+ HasSeparatingComment = i > 0;
+ }
MustBreakBeforeItem.push_back(ItemBegin->MustBreakBefore);
if (ItemBegin->is(tok::l_brace))
@@ -193,10 +196,9 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
ItemBegin = ItemEnd->Next;
}
- // If this doesn't have a nested list, we require at least 6 elements in order
- // create a column layout. If it has a nested list, column layout ensures one
- // list element per line.
- if (Commas.size() < 5 || Token->NestingLevel != 0)
+ // Don't use column layout for nested lists, lists with few elements and in
+ // presence of separating comments.
+ if (Token->NestingLevel != 0 || Commas.size() < 5 || HasSeparatingComment)
return;
// We can never place more than ColumnLimit / 3 items in a row (because of the