<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69342>69342</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format poor comment spacing with AlignArrayOfStructures
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kadler
</td>
</tr>
</table>
<pre>
Similar to #62904 I've also noticed weird alignment issues of comments inside array initializers when AlignArrayOfStructures is enabled:
test.c
```c
struct point {
int x, y;
}
struct point points[] = {
// test of single line comment
{0, 1},
/* this is a C-style comment */
{1, 2},
// overly indented comment
{3, 4},
/* overly indented C-style comment */
{0, 0}
};
```
```
clang-format -style="{ ContinuationIndentWidth: 8, AlignArrayOfStructures: Left }" test.c
```
```c
struct point {
int x, y;
}
struct point points[] = {
// test of single line comment
{0, 1},
/* this is a C-style comment */
{1, 2},
// overly indented comment
{3, 4},
/* overly indented C-style comment */
{0, 0}
};
```
```
clang-format -style="{ ContinuationIndentWidth: 8, AlignArrayOfStructures: Right }" test.c
```
```c
struct point {
int x, y;
}
struct point points[] = {
// test of single line comment
{0, 1},
/* this is a C-style comment */
{1, 2},
// overly indented comment
{3, 4},
/* overly indented C-style comment */
{0, 0}
};
```
```
clang-format -style="{ ContinuationIndentWidth: 8, AlignArrayOfStructures: None }" test.c
```
```c
struct point {
int x, y;
}
struct point points[] = {
// test of single line comment
{0, 1},
/* this is a C-style comment */
{1, 2},
// overly indented comment
{3, 4},
/* overly indented C-style comment */
{0, 0}};
```
When Using AlignArrayOfStructures with either Left or Right options, the indentation of the comments does not follow the indentation of the array contents. The first comment is indented two spaces while subsequent comments are indented one space. Neither IndentWidth nor ContinuationindentWidth seem to have any effect on this behavior.
This is with clang-format 16.0.6 from macOS Homebrew.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsls1u4zYQx5-GugwiUJQlxQcdnBhGFyh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