Skip to content

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

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading