<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75035>75035</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format Leave option for AlignTrailingComments is broken
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ChristophStrehle
</td>
</tr>
</table>
<pre>
looks like the Leave option for AlignTrailingComments is broken in clang-format 17.0.6 when using tabs for indentation.
When formatting the following code:
```
namespace mynamespace {
// My struct
struct MyStruct final {
constexpr int NoError{0}; //!< Successfully
constexpr int Error{1}; //!< Error
};
} // namespace mynamespace
```
with this command line:
`clang-format -style="{Language: Cpp, UseTab: Always, IndentWidth: 4, TabWidth: 4, AlignTrailingComments: {Kind: Leave}}"`
I get the following output after the first run:
```
namespace mynamespace {
// My struct
struct MyStruct final {
constexpr int NoError{0}; //!< Successfully
constexpr int Error{1}; //!< Error
};
} // namespace mynamespace
```
That means that clang-format will change the indentation of the trailing comments by replacing the tabs with spaces.
Even worse then the trailing comments is that clang-format will insert a space in front of the comment `// My struct` in the first run. In a second run clang-format will insert a second space, then a third space, then a tab and then two spaces again.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VVGPozYQ_jXmZbTImCSQBx42yUVa9a4vu9U9GxjAXWMje9g0_76yYXWb06ZSq56EkmE8_jzfzDdGeq96g1ix7YFtT4mcabCuOg5OebLT8EwOB41Jbdtrpa199aDVKwINCF9RviHYiZQ10FkHj1r15sVJpZXpj3Yc0ZAH5aF29hUNKAONlqZ_6KwbJUFWpDzdwWVAA7NXpgeStY9QyrRoSAbolPET44_L7_cQu2ynuGFA6KzW9hLeGtsiy9dQtuPrE1-NHNFPskEYrz9sVhzWaHFm4gzfruDJzQ0t3sWGb9fnxeiUkfrDJr5vrPGEf00hZYLf7RfnrGPFgbPixPID4_vwRHAmMpYf4XluGvS-m7W-3oF5B8nugiwRy-41ZrVhZfIp308rc1E0AA3KQ2PHUZoWtDI3dbzp2oOnq0aWn5gQrDh8laafZR_i4ThNTBzhD48vsg6OR32RVx98T7Gh31VLQ1jYBN-LrG8dnwoorLLi8JsybTCj6gLnIibwTuIJeqSf5GBnmmYC2RG6ZUk5T-Bm8x9FAr9IJQD_g0J-lTxeBkkwojQeKJg3YrgoraEZpOmXO-HD3ILtoovWfkZ1xRuhvoLDScvmfYLj2EcZxjT8zch_eUMDF-t8PMHcwVR3s1PGoyOQC3a4hDpnDb2ntyJA4Ptzd3c8hN8oJ4UnE7CwsaYNjn88cYlaaiuOS_4yzJr7xCtrCMO3kLzYtRYge6lMCklb5e0-38sEq6zgQpTFblcmQyUzbNuyzVvRtXyTlSVvMKtxX5RFt62zfaIqwUWeiSzj-03Gy1Q2ouZlmfP9pt7tas42HEepdKr125ha1yfK-xmrYsvzbaJljdrHD4QQH8mG8dueEleFbQ_13Hu24Vp58j-ASJHG6qZE__azkcxOVwPRFG6CpUW9omGu08aOTJzDWevfw-Tsn9gQE-fIwDNxjiT-DgAA___TYzUg">