Skip to content

Commit aa2a818

Browse files
committed
[clang-format] Align trailing comments for function parameters
before ```C++ void foo(int name, // name float name, // name int name) // name {} ``` after ```C++ void foo(int name, // name float name, // name int name) // name {} ``` Fixes #85123. As the bug report explained, the procedure for aligning the function parameters previously failed to update `StartOfTokenColumn`.
1 parent 70f7039 commit aa2a818

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
399399
}
400400
}
401401
}
402+
403+
// The scope to be aligned may not occupy entire lines. The rest of the line
404+
// needs some book-keeping.
405+
for (unsigned i = End; i < Changes.size() && Changes[i].NewlinesBefore == 0;
406+
++i) {
407+
Changes[i].StartOfTokenColumn += Shift;
408+
}
402409
}
403410

404411
// Walk through a subset of the changes, starting at StartAt, and find

clang/unittests/Format/FormatTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19828,6 +19828,14 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
1982819828
" Test &operator=(const Test &) = default;\n"
1982919829
"};",
1983019830
Alignment);
19831+
19832+
// The comment to the right should still align right.
19833+
verifyFormat("void foo(int name, // name\n"
19834+
" float name, // name\n"
19835+
" int name) // name\n"
19836+
"{}",
19837+
Alignment);
19838+
1983119839
unsigned OldColumnLimit = Alignment.ColumnLimit;
1983219840
// We need to set ColumnLimit to zero, in order to stress nested alignments,
1983319841
// otherwise the function parameters will be re-flowed onto a single line.

0 commit comments

Comments
 (0)