diff options
author | sstwcw <su3e8a96kzlver@posteo.net> | 2025-09-25 16:46:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-25 16:46:43 +0000 |
commit | a0c75a9009e0699ac98e9d0ca3edc913a77d606a (patch) | |
tree | 1807b62eba329e91924f4bc95f2610762498eefe /llvm/unittests/Support/CommandLineTest.cpp | |
parent | df420ee2ba3ce58b07f7ae70b32ebd649dcb0a5a (diff) | |
download | llvm-a0c75a9009e0699ac98e9d0ca3edc913a77d606a.zip llvm-a0c75a9009e0699ac98e9d0ca3edc913a77d606a.tar.gz llvm-a0c75a9009e0699ac98e9d0ca3edc913a77d606a.tar.bz2 |
[clang-format] Align within the level with Cpp11BracedListStyle disabled (#159140)
When the style is
`{AlignConsecutiveDeclarations: true, Cpp11BracedListStyle: false}`, the
program would sometimes align the lambda body with the outside. Like
this.
```C++
const volatile auto result{ []() {
const auto something = 1;
return 2;
} };
```
This patch stops it. Now the output looks like this.
```C++
const volatile auto result{ []() {
const auto something = 1;
return 2;
} };
```
Fixes #53699.
The problem was with how the `AlignTokenSequence` function tracked
levels. The stack was pushed once when a token was more nested than the
previous one. It was popped once when a token was less nested than the
previous one. With the option `Cpp11BracedListStyle` disabled, the `[`
token was deeper than the previous token by 2 levels. Both its
indentation level and nesting level were more than that of the previous
one. But the stack was only pushed once. The following tokens popped the
2 levels separately. The function treated the body of the lambda
expression as on the same level as the outside.
The problem is fixed this way. The function `AlignTokens` which calls
the function `AlignTokenSequence` already uses a simpler and more robust
way to track levels. It remembers the outermost level it should align.
It compares the token's level with the outermost level. It does not need
a stack. So it is immune to the problem. This patch makes the function
`AlignTokenSequence` take as a parameter the indices of the tokens
matched by the function `AlignTokens`. This way it does not have to
contain the logic again.
Now the function `AlignTokenSequence` only aligns tokens already matched
by the function `AlignTokens`. It is easy to see that the assertion on
line 453 holds. The workaround on line 354 is not needed any more. The
test on line 20310 added at the same time as the assertion ensures that
the assertion hold.
The stack in the function `AlignTokenSequence` is kept for now. It is
still used to figure out when things inside a level should move along
with the outer level. Since the stack has the problem, the developer
plans to move the logic into token annotator. It already uses a stack.
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
0 files changed, 0 insertions, 0 deletions