-
Notifications
You must be signed in to change notification settings - Fork 13.4k
A newline is added after a string token if the next 2 tokens are lessless and string #44363
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
Comments
This is a really annoying issue, especially because the results seem pretty random: If you use QStringLiteral() the strings are not wrapped. One workaround for the usecase you described would be to use initializer lists, which is formatted really well and looks even better IMHO. But in QTest::newRow() calls one can not use initializer lists and using QStringLiteral and such would add unwanted noise. Especially with the many usages in the KDE codebase this becomes a problem. For example: would be formatted to QTest::newRow("test") << "" I would appreciate if the developers could look into this :) |
Note that 'std::cout << "parameter " << "=" <<' gets split onto two lines... I would need to change this as 'std::cout << "parameter =" <<' This is a bug, see llvm/llvm-project/issues/44363
Using LLVM 15.0.0 on Windows we have a similar issue. connection_store_
<< some_module.signals().scanning_started.connect(
[this]()
{
/*business logic*/
})
<< some_module.signals().scanning_finished.connect(
[this](...)
{
/*business logic*/
}
}); Clang-format does this: connection_store_ << some_module.signals().on_started.connect(
[this]()
{
/*business logic*/
})
<< some_module.signals().on_finished.connect(
[this](...)
{
/*business logic*/
}
}); I suggest having an option allowing specific behaviour, something like
Anyone else having issues in general with the stream operators? |
same issue here, I agree with the above suggestion. |
@dan-42, it seems that clang-format 17 formats your example alright although the indent of the comments are wrong, which you can open another issue for. |
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
Instead, leave the line wrapping as is. Fixes llvm#43887. Fixes llvm#44363.
Extended Description
Given the code:
QStringList() << "something" << "something" << variable;
If I then run clang-format with the default config file, the output is the following code:
QStringList() << "something"
<< "something" << variable
What I expected, was that it stays on a single line, unless it exceeds the column limit and possible penalties. In this case, untouched.
It stays untouched when I add a variable in between:
QStringList() << "something" << a << "something" << variable;
Looking at the code, I noticed that somebody intentionally introduced this to split endline characters in commit df28f7b8dd6a032515109de4ff5b4067be95da8e (currently at lib/Format/TokenAnnotator.cpp, line 3073).
In the attachment I added a file with a slightly different example that I used when debugging clang-format.
The text was updated successfully, but these errors were encountered: