<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71825>71825</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format-18 `AlignTrailingComments: Kind: Leave` moves comments #4
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MartinsSmirnovs
</td>
</tr>
</table>
<pre>
Given following `.clang-format` file:
```
AlignArrayOfStructures: Left
AlignTrailingComments:
Kind: Leave
IndentWidth: 4
```
And following `foo.cpp` source file:
```
#include <string>
#include <vector>
struct Foo {
std::string text;
int number;
};
const std::vector<Foo> table1 = {
// This is a comment
// The purpose of comments is to describe what and why is going on in code
// Specifically this comment here is for the demonstration of clang-format's
// bug
{"Hello", 1},
{"There", 2},
{"!", 3},
};
```
I expect that `clang-format foo.cpp` will not move comments, however, it does:
```
$ clang-format foo.cpp
#include <string>
#include <vector>
struct Foo {
std::string text;
int number;
};
const std::vector<Foo> table1 = {
// This is a comment
// The purpose of comments is to describe what and why is going on in code
// Specifically this comment here is for the demonstration of clang-format's
// bug
{"Hello", 1},
{"There", 2},
{"!", 3},
};
```
Looks like the comments get moved to the default `IndentWidth` of `2`.
`clang-format` version:
```
$ clang-format --version
Ubuntu clang-format version 18.0.0 (++20230929042255+ab472cd4ea12-1~exp1~20230929042400.1214)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzclc1y2zYQx58GuuxIgw-KIg88SHLUZppOD3anZ5BckmhAgAOAkn3Js3dAyRIVO016yKUeD0RhF7v7X_zEld6r1iAWZL0j64eFHENnXfG7dEEZ_9grZ-zRL0pbvxS_qCMaaKzW9qRMCySlq0pL0y4b63oZSEqhURqJ2BL6QOiWpPTyP33datWarXPy5Y_mMbixCqNDT8QWPmETZj5PTiqtTLu3fY8m-GtAAIDflKnPZ-QRz9sfTY0m_KXq0EVL8n52U9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