| Issue |
165932
|
| Summary |
[clang-format] Incorrect spacing with `AlignArrayOfStructures: Left` in parenthesized lists with trailing commas inside brace initializers
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
dhmjhu
|
With `AlignArrayOfStructures: Left` enabled, clang-format adds spurious spaces to certain expressions inside nested brace initializers. It's kind of hard to explain precisely, so I made a simplified example:
Running `clang-format -style="{AlignArrayOfStructures: Left}"` on
```c++
#define MACRO(a, ...) (a)
struct TestStruct {
int a1[1];
int a2[1];
} test = {
{
MACRO(1, 3, 235, 12, -1, 99, 0),
},
{
MACRO(8, 9, 5, 1, 62, 5, 101),
},
};
```
results in
```c++
#define MACRO(a, ...) (a)
struct TestStruct {
int a1[1];
int a2[1];
} test = {
{
MACRO(1, 3, 235, 12, -1, 99, 0),
},
{
MACRO(8, 9, 5, 1, 62, 5, 101),
},
};
```
I'm not sure what it *should* look like, but definitely not that.
As far as I can tell, this occurs when:
- each inner macro invocation (or parenthesized list) has the same number of comma-separated arguments, and
- each inner list is followed by a trailing comma.
If the lists have different numbers of elements, it seems `AlignArrayOfStructures` won't touch it—so they just end up separated by single spaces.
This also occurs when using designated initializers (which is how I originally encountered the issue).
The attached example file might make the required conditions clearer. (It also contains some bonus strange behavior at the end that I didn't have time
to look into.)
I was able to reproduce this using:
- the official LLVM 21.1.4 release for 64-bit Windows
- whatever version is bundled with the VS Code C/C++ extension
- Debian's clang-format 19.1.7 (`Debian clang-format version 19.1.7 (7)`)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs