[clang] [clang-format] unexpected break after binOp '<<' (PR #69859)

Tsarkov Maksim via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 21 17:00:37 PDT 2023


s1Sharp wrote:

I have no way to link the issues related to the PR issue. I don't know why, but add a link to issue to this comment https://github.com/llvm/llvm-project/issues/44363 .
So, I want to start a little discussion about the solution.

I'll start with the problem - when using the BreakBeforeBinaryOperators: None option, I expect that the code
```C++
std::cout << "hello " << "world!";
```
with binary output operation to stream via token "<<" (tok::lessless)
clang-format output is:
```C++
std::cout << "hello "
                     << "world!";
```
This was unexpected for me and unnecessary, as well as for other users who have already created issues.
The token '<<' is a binary operator that have link to the "BreakBeforeBinaryOperators" option.

1th solution is: Apply the break of the binary operator '<<' only if BreakBeforeBinaryOperators is [All | NonAssignment].And npt break if BreakBeforeBinaryOperators is None. This solution is very simple, but, in my opinion, violates the user api and the user's expectations of the clang-format program.

2th solution is: Add new option that allowing specific behaviour, such as "BreakAfterStreamOperator" or "BreakAfterLessLessOperator" with options [ Leave | NoFitLine | All ].


I am open to discussions


https://github.com/llvm/llvm-project/pull/69859


More information about the cfe-commits mailing list