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

Commit bfbaed9

Browse files
committed
clang-format: Fix column layout with a comment in the last line.
Before: int aaaaa[] = { 1, 2, 3, // comment 4, 5, 6 // comment }; After: int aaaaa[] = { 1, 2, 3, // comment 4, 5, 6 // comment }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242299 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 83bcf1c commit bfbaed9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: lib/Format/FormatToken.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
183183
ItemEnd = Token->MatchingParen;
184184
const FormatToken *NonCommentEnd = ItemEnd->getPreviousNonComment();
185185
ItemLengths.push_back(CodePointsBetween(ItemBegin, NonCommentEnd));
186-
if (Style.Cpp11BracedListStyle) {
186+
if (Style.Cpp11BracedListStyle &&
187+
!ItemEnd->Previous->isTrailingComment()) {
187188
// In Cpp11 braced list style, the } and possibly other subsequent
188189
// tokens will need to stay on a line with the last element.
189190
while (ItemEnd->Next && !ItemEnd->Next->CanBreakBefore)

Diff for: unittests/Format/FormatTest.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6307,6 +6307,11 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
63076307
" 1111111111, 2222222222, 33333333333, 4444444444, //\n"
63086308
" 111111111, 222222222, 3333333333, 444444444, //\n"
63096309
" 11111111, 22222222, 333333333, 44444444};");
6310+
// Trailing comment in the last line.
6311+
verifyFormat("int aaaaa[] = {\n"
6312+
" 1, 2, 3, // comment\n"
6313+
" 4, 5, 6 // comment\n"
6314+
"};");
63106315

63116316
// With nested lists, we should either format one item per line or all nested
63126317
// lists one on line.

0 commit comments

Comments
 (0)