-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-format] Don't break between string literal operands of << #69871
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
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFixes #44363. Full diff: https://github.com/llvm/llvm-project/pull/69871.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 7f85f48de2ed2ed..e185afaa2885123 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5118,10 +5118,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
return true;
if (Left.IsUnterminatedLiteral)
return true;
- if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
- Right.Next->is(tok::string_literal)) {
- return true;
- }
if (Right.is(TT_RequiresClause)) {
switch (Style.RequiresClausePosition) {
case FormatStyle::RCPS_OwnLine:
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 0a87cfc4f1d6af9..0841ea1bcb66fa9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26459,6 +26459,10 @@ TEST_F(FormatTest, AllowBreakBeforeNoexceptSpecifier) {
Style);
}
+TEST_F(FormatTest, StreamOutputOperator) {
+ verifyFormat("std::cout << \"foo\" << \"bar\" << baz;");
+}
+
} // namespace
} // namespace test
} // namespace format
|
this is good to be respectful. Please, lets check my mr #69859 also |
I think adding the possibility of breaking '<<' is a good idea if it's optional, what do u think? |
+1, but see also #69859 (comment). |
We have noticed that after this change, (I'm using For example, if the input is
the output format would be the same before and after this change. However, if the input is
prior to this change we would reformat it as
but after this change we would format it as
that is the same as input. Is that behavior intentional? |
IMO, the new behavior is consistent with the documentation for |
I wish we'd made this removal an option rather than just removing it, what we are seeing is reasonably formatted json or xml being streamed out is now poorly written osjson << "{\n"
<<" \"name\": \"value\",\n"
<<" \"key\": \"abc\", \n"
<<" }"; now becomes osjson << "{\n" <<" \"name\": \"value\",\n <<" \"key\": \"abc\",\n << "}"; While i understand its correct for column width its not as nicer. These rules about breaking between << were part of the original author rules for now to best try and format c++ and I sort of feel we should at least honour it via an option. I also feel that this will create a large amount of complaints about us changing defaults. |
see #88483 |
What version was used? I've just tried clang-format 18.1.3, and it's totally fine:
|
Fixes #44363.