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

// Pass to the function entire lines, so it can update the state of all tokens
// that move.
EndOfSequence = I;
while (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 the parent 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