llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) <details> <summary>Changes</summary> …ing literals (#<!-- -->92214) --- Full diff: https://github.com/llvm/llvm-project/pull/94091.diff 2 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+5-3) - (modified) clang/unittests/Format/FormatTest.cpp (+11) ``````````diff 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" `````````` </details> https://github.com/llvm/llvm-project/pull/94091 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits