[clang-format] Align trailing comments for function parameters (#164458)
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`.
This commit is contained in:
parent
388ef61250
commit
3a2de951a4
@ -516,7 +516,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;
|
||||
@ -660,8 +661,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;
|
||||
}
|
||||
|
||||
|
||||
@ -19851,6 +19851,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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user