-
Notifications
You must be signed in to change notification settings - Fork 13.5k
release/18.x: [clang-format] Don't always break before << between str… #94091
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) Changes…ing literals (#92214) Full diff: https://github.com/llvm/llvm-project/pull/94091.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c1f1662481922..628fe46cc348e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5159,9 +5159,11 @@ 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 (const auto *BeforeLeft = Left.Previous, *AfterRight = Right.Next;
+ BeforeLeft && BeforeLeft->is(tok::lessless) &&
+ Left.is(tok::string_literal) && Right.is(tok::lessless) && AfterRight &&
+ AfterRight->is(tok::string_literal)) {
+ return Right.NewlinesBefore > 0;
}
if (Right.is(TT_RequiresClause)) {
switch (Style.RequiresClausePosition) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 0161a1685eb12..d69632f7f0f8c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10426,6 +10426,17 @@ TEST_F(FormatTest, KeepStringLabelValuePairsOnALine) {
" bbbbbbbbbbbbbbbbbbbbbbb);");
}
+TEST_F(FormatTest, WrapBeforeInsertionOperatorbetweenStringLiterals) {
+ verifyFormat("QStringList() << \"foo\" << \"bar\";");
+
+ verifyNoChange("QStringList() << \"foo\"\n"
+ " << \"bar\";");
+
+ verifyFormat("log_error(log, \"foo\" << \"bar\");",
+ "log_error(log, \"foo\"\n"
+ " << \"bar\");");
+}
+
TEST_F(FormatTest, UnderstandsEquals) {
verifyFormat(
"aaaaaaaaaaaaaaaaa =\n"
|
@tstellar can we also get this one into 18.1.7? |
@owenca I'm only going to take regression fixes for 18.1.7. |
@tstellar strictly speaking, this is a regression fix. (It's a churn within 18.x release cycle.)
|
@owenca Do you have a release note we can put in the release announcement? |
…ing literals (#92214)