llvm / llvm/llvm-project

[clang-format] Misaligned trailing comment on default case with `AlignConsecutiveShortCaseStatements`

Open
#161,973 1 comment 0 reactions 0 assignees View on GitHub
clang-format
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

With this config:
```yaml
AllowShortCaseLabelsOnASingleLine: true
AlignConsecutiveShortCaseStatements:
Enabled: true
```

Trailing comments on "short default statements" are misaligned if other trailing comments are present.
For this to occur *at least one* case label has to be longer than the `default` label.

```cpp
switch (state) {
case State::Idle: return 1; // Aligned
case State::Running: return 2; // Aligned
default: return 3; // Oops!
};
```

Interestingly, the alignment is only affected by the length of the case label, not the whole statement.

*Tested with version `18.1.3 (Ubuntu)` and `22.0.0git (commit 3c39187)`*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.