-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang-format] unexpected break after binOp '<<' #69859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 #44363 . I'll start with the problem - when using the BreakBeforeBinaryOperators: None option, I expect that the code std::cout << "hello " << "world!"; with binary output operation to stream via token "<<" (tok::lessless) std::cout << "hello "
<< "world!"; This was unexpected for me and unnecessary, as well as for other users who have already created issues. 1th solution is: Apply the break of the binary operator '<<' only if BreakBeforeBinaryOperators is [All | NonAssignment]. And not 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 |
the problem occurred while checking for the correctness of the break after binary operators. The output statement 'tok::lessless' is then break line every possible time, which is not expected with the BreakBeforeBinaryOperators: None Fixes llvm#59797 Fixes llvm#44363
Please add unit tests in |
We need a comprehensive solution to cover the following:
|
What Owen says. And given that the modified lines were removed, maybe the issue(s) are also gone? To the review unrelated, why didn't it get the @llvm/pr-subscribers-clang-format thing? |
yes, issue with breaking after << is gone. I want to get your point about functionality clang-format and implementing new option such as "BreakAfterStreamOperator". As i can see, @HazardyKnusperkeks you agree with "owenca" point? May be i can do something with this feature |
You are welcome to try. I'd go with the name
You can of course start with documentation and/or tests to show how you think it will work, even if you did not try to implement it. |
@s1Sharp are there any conclusions here? our code also incidentally relied on having new lines between string literals, mostly for the sake of having a line break after string literals that end with what do people think about restoring the functionality to break after string literals that end with |
sent out #76795 for implementation |
First, I want to show how this works with the current code. .clang-format:
before clang-format: cout << "hello\n" << "World\n" << "HELLO" << "world" << "hello" << "World" << "HELLO" << "world" << "hello" << "World" << "HELLO" << "world";
cout << "hello" << std::endl << "World" << "hello" << '\n' << "another hello" << "world";
cout << "hello\n"
<< "World" << std::endl
<< "HELLO" << "world"; after clang-format: cout << "hello\n"
<< "World\n"
<< "HELLO" << "world" << "hello" << "World" << "HELLO"
<< "world" << "hello" << "World" << "HELLO" << "world";
cout << "hello" << std::endl
<< "World" << "hello" << '\n'
<< "another hello" << "world";
cout << "hello\n" << "World" << std::endl << "HELLO" << "world";
A bit unexpected results, right? Formatting applies to single-line expressions and breaks to another line after the \n and std::endl characters. And if the code has already been manually formatted (as in 3rd cout), then clang-format groups this code into a single-line expression. I agree with your suggestion that to maintain compatibility with the old behavior of clang-format. |
This restores a subset of functionality that was forego in d68826d. Streaming multiple string literals is rare enough in practice, hence that change makes sense in general. But it seems people were incidentally relying on this for having line breaks after string literals that ended with `\n`. This patch tries to restore that behavior to prevent regressions in the upcoming LLVM release, until we can implement some configuration based approach as proposed in llvm#69859.
…76795) This restores a subset of functionality that was forego in d68826d. Streaming multiple string literals is rare enough in practice, hence that change makes sense in general. But it seems people were incidentally relying on this for having line breaks after string literals that ended with `\n`. This patch tries to restore that behavior to prevent regressions in the upcoming LLVM release, until we can implement some configuration based approach as proposed in #69859.
…lvm#76795) This restores a subset of functionality that was forego in d68826d. Streaming multiple string literals is rare enough in practice, hence that change makes sense in general. But it seems people were incidentally relying on this for having line breaks after string literals that ended with `\n`. This patch tries to restore that behavior to prevent regressions in the upcoming LLVM release, until we can implement some configuration based approach as proposed in llvm#69859.
closed due to inactivity |
the problem occurred while checking for the correctness of the break after binary operators. The output statement 'tok::lessless' is then break line every possible time, which is not expected with the BreakBeforeBinaryOperators: None
Fixes #59797
Fixes #44363