Skip to content
Merged
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
12 changes: 10 additions & 2 deletions clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
};

unsigned I = StartAt;
for (unsigned E = Changes.size(); I != E; ++I) {
const auto E = Changes.size();
for (; I != E; ++I) {
auto &CurrentChange = Changes[I];
if (CurrentChange.indentAndNestingLevel() < IndentAndNestingLevel)
break;
Expand Down Expand Up @@ -650,8 +651,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 < E && 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