diff options
| author | sstwcw <su3e8a96kzlver@posteo.net> | 2025-10-15 15:18:11 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-15 15:18:11 +0000 |
| commit | a0b8261610395c3ef121958417251f552d6c1bb5 (patch) | |
| tree | 6e93a8f79c1adbc020534ced564b93ef0601d51f /clang/lib/Frontend/CompilerInvocation.cpp | |
| parent | 7d3729d381a0d6d091e4f4929b9a5f06f6cba906 (diff) | |
| download | llvm-a0b8261610395c3ef121958417251f552d6c1bb5.zip llvm-a0b8261610395c3ef121958417251f552d6c1bb5.tar.gz llvm-a0b8261610395c3ef121958417251f552d6c1bb5.tar.bz2 | |
[clang-format] Continue aligned lines better (#161903)
Fixes #53497.
Fixes #56078.
after with config `{AlignConsecutiveAssignments: true}`
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = [] {
x = {.one_foooooooooooooooo = 2, //
.two_fooooooooooooo = 3, //
.three_fooooooooooooo = 4};
};
A B = {"Hello "
"World"};
BYTE payload = 2;
float i2 = 0;
auto v = type{i2 = 1, //
i = 3};
```
before
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = [] {
x = {.one_foooooooooooooooo = 2, //
.two_fooooooooooooo = 3, //
.three_fooooooooooooo = 4};
};
A B = {"Hello "
"World"};
BYTE payload = 2;
float i2 = 0;
auto v = type{i2 = 1, //
i = 3};
```
When a line gets aligned, the following lines may need to move with it.
This patch replaces the old algorithm with a simpler one. It uses the
`IsAligned` attribute. It makes most of the scope stack irrelevant.
Now the stack only needs to keep track of 2 levels.
The old algorithm had problems like these.
- Whether lines inside a braced list moved depended on whether there was
a type at the start. It should depend on whether the inside was
aligned to the brace. The first case that came up with a type name at
the start happened to have a comma at the end of the list so the
inside was not aligned to the brace.
- Excluding lines inside closures did not always work.
- A continued string could move twice as much as it should.
The following problems are not fixed yet.
A token that opens a scope is needed. Operator precedence is not
enough.
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = 0 + //
0;
```
The algorithm has trouble when things that should not move and things
that should move are nested. This is related to the `IsAligned`
attribute being a boolean. It also affects how spaces and tabs are
selected.
```C++
auto aaaaaaaaaaaaaaaaaaaaa = {};
auto b = {.a = {
.a = 0,
}};
```
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions
