]> granicus.if.org Git - clang/commitdiff
clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0
authorDaniel Jasper <djasper@google.com>
Tue, 20 Jan 2015 12:59:20 +0000 (12:59 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 20 Jan 2015 12:59:20 +0000 (12:59 +0000)
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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index 7cf1c844678552f51206bf04b9a2583853f2111c..c08c138e1b2e0c5f664692331e0e425069d709fa 100644 (file)
@@ -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;
 }
index 615b46a1d4ee280431d86d054037df394b27831c..436835b76ca6ef21a1e8acbfb8e9c1757f3a3960 100644 (file)
@@ -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) {