From: Daniel Jasper Date: Tue, 20 Jan 2015 12:59:20 +0000 (+0000) Subject: clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be285ccf09bee2c343750cb3386b8e00751ccdad;p=clang clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0 Before: const char *x = "hello llvm"; After: const char *x = "hello llvm"; This fixes llvm.org/PR22245. Patch by Bill Meltsner, thank you! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226564 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 7cf1c84467..c08c138e1b 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -1081,8 +1081,9 @@ bool ContinuationIndenter::nextIsMultilineString(const LineState &State) { if (Current.getNextNonComment() && Current.getNextNonComment()->isStringLiteral()) return true; // Implicit concatenation. - if (State.Column + Current.ColumnWidth + Current.UnbreakableTailLength > - Style.ColumnLimit) + if (Style.ColumnLimit != 0 && + State.Column + Current.ColumnWidth + Current.UnbreakableTailLength > + Style.ColumnLimit) return true; // String will be split. return false; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 615b46a1d4..436835b76c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4611,6 +4611,9 @@ TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) { format("NSString *const kString = @\"aaaa\"\n" "\"bbbb\";", Break)); + + Break.ColumnLimit = 0; + verifyFormat("const char *hello = \"hello llvm\";", Break); } TEST_F(FormatTest, AlignsPipes) {