diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 35dc182a2d1e08609c613082b9ccbb254678dc00..9311ca481c344729ec80faa05ed49f56e8a16594 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -961,6 +961,12 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, break; } + // When breaking before a tab character, it may be moved by a few columns, + // but will still be expanded to the next tab stop, so we don't save any + // columns. + if (NewRemainingTokenColumns == RemainingTokenColumns) + break; + assert(NewRemainingTokenColumns < RemainingTokenColumns); if (!DryRun) Token->insertBreak(LineIndex, TailOffset, Split, Whitespaces); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 708ddfa09136875a0d2d31a9c32c3ba2650365f3..f1442e03b6897ab9261b626b942811453d9ec776 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6366,7 +6366,7 @@ TEST_F(FormatTest, ReformatRegionAdjustsIndent) { 67, 0, getLLVMStyle())); } -TEST_F(FormatTest, BreakStringLiterals) { +TEST_F(FormatTest, BreaksStringLiterals) { EXPECT_EQ("\"some text \"\n" "\"other\";", format("\"some text other\";", getLLVMStyleWithColumns(12))); @@ -6526,6 +6526,16 @@ TEST_F(FormatTest, BreakStringLiterals) { format("#define A \"some text other\";", AlignLeft)); } +TEST_F(FormatTest, BreaksStringLiteralsWithTabs) { + EXPECT_EQ( + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "(\n" + " \"x\t\");", + format("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaa(" + "\"x\t\");")); +} + TEST_F(FormatTest, BreaksWideAndNSStringLiterals) { EXPECT_EQ( "u8\"utf8 string \"\n"