<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92530>92530</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format option AlignTrailingComments: Leave misaligns comment-only lines
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MatejVitek
</td>
</tr>
</table>
<pre>
I'm using clang-format in VS Code with the following setup:
"C_Cpp.clang_format_style": "{BasedOnStyle: LLVM, UseTab: ForIndentation, IndentWidth: 4, TabWidth: 4, ColumnLimit: 0, PointerAlignment: Left, BreakBeforeBraces: Attach, SortIncludes: CaseInsensitive, AllowShortIfStatementsOnASingleLine: Never, AlignTrailingComments: Leave, SpacesBeforeTrailingComments: 2, SpaceBeforeCaseColon: false, InsertNewlineAtEOF: true}",
However, this setup is indenting my comment lines incorrectly. My expected result would look like:
int main(int argc, char* argv[]) {
// create 10 threads
pthread_t threads[10];
for (int i = 0; i < 10; i++)
pthread_create(&threads[i], NULL, thread, NULL);
// wait for a bit then stop the threads
sleep(3);
for (int i = 0; i < 10; i++) {
// pthread_yield(); // deprecated
sched_yield();
pthread_cancel(threads[i]); // cancel thread
}
}
However, the result of formatting with the above setup is the following:
int main(int argc, char* argv[]) {
// create 10 threads
pthread_t threads[10];
for (int i = 0; i < 10; i++)
pthread_create(&threads[i], NULL, thread, NULL);
// wait for a bit then stop the threads
sleep(3);
for (int i = 0; i < 10; i++) {
// pthread_yield(); // deprecated
sched_yield();
pthread_cancel(threads[i]); // cancel thread
}
}
This seems to be caused by the setting `AlignTrailingComments: Leave`. Setting this option to either `Never` or `Always` works fine with comment-only lines (but obviously changes the behaviour for actual trailing comments).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVstu6zYQ_Rp6M4ghU35p4YUfNRrANyng3HQZUNRI4g1FCuTIrv--oOjYcZK2KNBFW8CwyJn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