[llvm-branch-commits] [clang] 8c0fe0d - release/18.x: [clang-format] Don't always break before << between str… (#94091)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jun 5 14:55:54 PDT 2024
Author: Owen Pan
Date: 2024-06-05T14:55:50-07:00
New Revision: 8c0fe0d65ed85966c0ac075e896620c55ca95227
URL: https://github.com/llvm/llvm-project/commit/8c0fe0d65ed85966c0ac075e896620c55ca95227
DIFF: https://github.com/llvm/llvm-project/commit/8c0fe0d65ed85966c0ac075e896620c55ca95227.diff
LOG: release/18.x: [clang-format] Don't always break before << between str… (#94091)
…ing literals (#92214)
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
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"
More information about the llvm-branch-commits
mailing list