diff options
author | sstwcw <su3e8a96kzlver@posteo.net> | 2024-01-29 05:24:51 +0000 |
---|---|---|
committer | sstwcw <su3e8a96kzlver@posteo.net> | 2024-02-06 05:02:12 +0000 |
commit | 617602d4f23e89e56afd0f550bcf72deb83ed0cb (patch) | |
tree | 79d4606aea3a43d30bd3f752df4eedd0f8e0dc02 /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 942cb2427a0e19f63b2f5b7da3d3fa6a594df3fe (diff) | |
download | llvm-617602d4f23e89e56afd0f550bcf72deb83ed0cb.zip llvm-617602d4f23e89e56afd0f550bcf72deb83ed0cb.tar.gz llvm-617602d4f23e89e56afd0f550bcf72deb83ed0cb.tar.bz2 |
[clang-format] Handle generic selections inside parentheses (#79785)
new
```C
while (_Generic(x, //
long: x)(x) > x) {
}
while (_Generic(x, //
long: x)(x)) {
}
```
old
```C
while (_Generic(x, //
long: x)(x) > x) {
}
while (_Generic(x, //
long: x)(x)) {
}
```
In the first case above, the second line previously aligned to the open
parenthesis. The 4 spaces did not get added by the fallback line near
the end of getNewLineColumn because there was already some indentaton.
Now the spaces get added explicitly.
In the second case above, without the fake parentheses, the second line
did not respect the outer parentheses, because the LastSpace field did
not get set without the fake parentheses. Now the indentation of the
outer level is used instead.
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index a3aca4a..671ae54 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1702,8 +1702,11 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, // Special case for generic selection expressions, its comma-separated // expressions are not aligned to the opening paren like regular calls, but // rather continuation-indented relative to the _Generic keyword. - if (Previous && Previous->endsSequence(tok::l_paren, tok::kw__Generic)) - NewParenState.Indent = CurrentState.LastSpace; + if (Previous && Previous->endsSequence(tok::l_paren, tok::kw__Generic) && + State.Stack.size() > 1) { + NewParenState.Indent = State.Stack[State.Stack.size() - 2].Indent + + Style.ContinuationIndentWidth; + } if ((shouldUnindentNextOperator(Current) || (Previous && |