<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140535>140535</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Formatting requires two passes to stabilize due to column miscalculation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rocfu
</td>
</tr>
</table>
<pre>
Hi,
I've discovered that the following C++ code requires two formatting passes to stabilize:
Source code: column 120
```cpp
int aaaaaaaaaaaaaaa = bbbbbbbbbbbbbbbbbbbbbbbbbbbb; //testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte
```
After the first pass, a space is added after the `//`, making it column 121
```cpp
int aaaaaaaaaaaaaaa = bbbbbbbbbbbbbbbbbbbbbbbbbbbb; // testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte
```
After the second pass, the line breaks
```cpp
int aaaaaaaaaaaaaaa =
bbbbbbbbbbbbbbbbbbbbbbbbbbbb; // testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte
```
I suspect that the first formatting pass doesn't account for the added space after the `//` when calculating the column, which causes the second pass to detect that column=121 > ColumnLimit, resulting in the line break.
My environment:
- clang-format version 17.0.6 and version 18.1.4
.clang-format configuration:
```yaml
Language: Cpp
ColumnLimit: 120
ReflowComments: true
SpacesInLineCommentPrefix:
Minimum : 1
Maximum : 1
```
Thank you for looking into this issue!
Best regards
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVdtu8zYMfhr5hqghy3HSXPjCSResQAsM-_cCskTbWmXJ0yH5u6cfJGdtUxTDgG2YkMAGT-LHj6S592o0iC1pDqR5KHgMk3Wts2KIRW_la_ujIuxIaEdo90jY7owglRf2jA4lhIkHCBPCYLW2F2VGOBJ2IOwAwkoEh79F5dBDuFgYrJt5CMlo4d4nqQUfeK-0-h1J3a23fLPRCcz-pO5AWB1nAxWjSb2l608sC6GdMgH47QFSP0D_F4fUByDsRNgpoA__7P8xozX5bgjo1ooo50MGStgROPiFCwTlgUuJEvibYfLN-eSXI8z8JZVIhXfo1b8NHf5b7B6FNfINfBJpZRB6h_zF_20whHb_J55H8NEvKMKHNs-kfmpkkBa9IWwXgAtho8kW2X7leqX-a8bhMqEBwbWImueQyWJlPtXuMikxgeAxz8ttbdP8SAxvGV696oeKVUDqH-CYBU9qViHFcuijznco84mUcoX8_ApozspZM6MJ60jegdDcjHcrajij88oaqHYlLbfAjXwX3ZdVuYE1VHnjJawZ1BgdD8qa66j_We1XPmtCuyduxsjHPPTpHJclhfqIoe7SHkhKQrufcdD2crRzStUnXXAx0fgtlds_midl8Kr-yeGgvq_3Ajwro-Y4Q46XJM_8-43gUyP8MnHzAq82Zl61teuAmmAhTMqD8j4iWaeUdgf0ARyO3ElfyLaW-3rPC2yr3Wa3bbYVq4upFX296-9rbNi231I5bKt9I6vN_r665wMd9oVqGWUNbap9xSijdTmIoaZc9KzZ803fb8mG4syVLrU-z6V1Y5HTaKsNbeqm0LxH7fNaZ-wjFYSxtOhdm_zu-jh6sqFa-eDfIwUVdP4k3Dg2D3B67_yb1f7FPgcZMQmuS2xW_q3JrSmi0-0UwpJ4W2dhVGGKfSnsTNgpZXJ93C3O_ooiEHbKAD1hpyvGc8v-CAAA__89BEDg">