Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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: 8 additions & 1 deletion clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,15 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
MatchedIndices.push_back(I);
}

EndOfSequence = I;
// Pass entire lines to the function so that it can update the state of all
// tokens that move.
for (EndOfSequence = I; EndOfSequence < Changes.size() &&
Changes[EndOfSequence].NewlinesBefore == 0;
++EndOfSequence) {
}
AlignCurrentSequence();
// The return value should still be where the level ends. The rest of the line
// may contain stuff to be aligned within an outer level.
return I;
}

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
Loading