Issue 140535
Summary [clang-format] Formatting requires two passes to stabilize due to column miscalculation
Labels clang-format
Assignees
Reporter rocfu
    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
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to