From: Alexander Kornienko Date: Tue, 15 Apr 2014 14:52:43 +0000 (+0000) Subject: Fix assertion when breaking string literals with tab characters. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47caeab34c7b4bdf1bb0e5aa0daaa2b587dbce20;p=clang Fix assertion when breaking string literals with tab characters. Summary: Fixes http://llvm.org/PR19368 Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D3379 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206295 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 35dc182a2d..9311ca481c 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 708ddfa091..f1442e03b6 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"