Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
}
}
}

// The scope to be aligned may not occupy entire lines. The rest of the line
// needs some book-keeping.
for (unsigned i = End; i < Changes.size() && Changes[i].NewlinesBefore == 0;
++i) {
Changes[i].StartOfTokenColumn += Shift;
if (i + 1 != Changes.size())
Changes[i + 1].PreviousEndOfTokenColumn += Shift;
}
}

// Walk through a subset of the changes, starting at StartAt, and find
Expand Down
8 changes: 8 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19828,6 +19828,14 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
" Test &operator=(const Test &) = default;\n"
"};",
Alignment);

// The comment to the right should still align right.
verifyFormat("void foo(int name, // name\n"
" float name, // name\n"
" int name) // name\n"
"{}",
Alignment);

unsigned OldColumnLimit = Alignment.ColumnLimit;
// We need to set ColumnLimit to zero, in order to stress nested alignments,
// otherwise the function parameters will be re-flowed onto a single line.
Expand Down