llvm / llvm/llvm-project

clang-format: `UseTab` interfering with `AlignConsecutiveAssignments`

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

Description

To reproduce: (in clang-format version 21.1.6)
```yaml
UseTab: ForContinuationAndIndentation
AlignConsecutiveAssignments: Consecutive
TabWidth: 8
IndentWidth: 8
ContinuationIndentWidth: 8
```

Which produces the following formatting (visualised):
```c
int⋅main(void)⋅{
» long⋅nmem,⋅size;
» struct⋅dynarr⋅arr;

» long⋅len⋅=⋅nmem⋅*⋅size;
» arr⋅⋅⋅⋅⋅⋅=⋅{
⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅nmem,
⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅malloc(len),
⋅⋅⋅⋅⋅⋅⋅⋅};
}
```
One part of the problem, seems from the looks of it, is that it (correctly) aligns the `=` symbol, but then fails to "switch back" to tabulations afterwards for some reason.

Beyond that, I have tested using `UseTab=Always` instead, here it seems the issue has magnified, since now it breaks alignment entirely:
```c
int⋅main(void)⋅{
» long⋅nmem,⋅size;
» struct⋅dynarr⋅arr;

» long⋅len⋅=⋅nmem⋅*⋅size;
» arr» ⋅=⋅{
» » ⋅⋅⋅⋅⋅nmem,
» » ⋅⋅⋅⋅⋅malloc(len),
» ⋅⋅⋅⋅⋅};
}
```
Where it seems to be appending 5 spaces for reasons unknown to me.

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.