| Issue |
242373
|
| Summary |
[clang-format] BlockIndent column-aligns a trailing member access to the opening parenthesis
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
Arteiimis
|
## Summary
Follow-up to #220327. With block indentation (`AlignAfterOpenBracket: true`
together with `BreakAfterOpenBracket*`/`BreakBeforeCloseBracket*`, which is what
`AlignAfterOpenBracket: BlockIndent` maps to), a line break before a member
access that follows a call is indented to the column of the enclosing opening
parenthesis instead of the block indent. The nested argument indentation that
#220327 reported is fixed separately; the trailing member access is still
column-aligned.
## Repro
```yaml
BasedOnStyle: LLVM
ColumnLimit: 90
IndentWidth: 2
ContinuationIndentWidth: 2
AlignAfterOpenBracket: BlockIndent
BreakBeforeBinaryOperators: NonAssignment
```
Input:
```cpp
void f() {
auto const nowMs = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
(void)nowMs;
}
```
Actual output (the argument is now block indented, the `.count()` line is not):
```cpp
void f() {
auto const nowMs =
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()
)
.count());
(void)nowMs;
}
```
Expected (no column alignment in block indentation mode; this is what
`AlignAfterOpenBracket: false` with the same break options already produces):
```cpp
void f() {
auto const nowMs =
static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
(void)nowMs;
}
```
## Analysis
In `ContinuationIndenter::getNewLineColumn()` the continuation indent for a
member access is
```cpp
const auto ContinuationIndent =
std::max(IndentationAndAlignment(CurrentState.LastSpace),
CurrentState.Indent) +
Style.ContinuationIndentWidth;
```
In block indentation mode `CurrentState.Indent` is the column-aligned position
of the enclosing opening parenthesis: `addTokenOnCurrentLine()` assigns
`CurrentState.Indent = State.Column + Spaces` for the first token inside the
bracket because `AlignAfterOpenBracket` is `true` in that mode, and
`CurrentState.LastSpace` is set to the same column when the enclosing bracket is
followed by a member access. Both values therefore point at the aligned column,
and the member access is indented relative to it instead of the block indent.
Not specific to casts: the same input without a cast reproduces it.
Not a regression from the 22 release: 19.1.7 formats the same way.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs