r226564 - clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0

Daniel Jasper djasper at google.com
Tue Jan 20 04:59:20 PST 2015


Author: djasper
Date: Tue Jan 20 06:59:20 2015
New Revision: 226564

URL: http://llvm.org/viewvc/llvm-project?rev=226564&view=rev
Log:
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!

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=226564&r1=226563&r2=226564&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Jan 20 06:59:20 2015
@@ -1081,8 +1081,9 @@ bool ContinuationIndenter::nextIsMultili
   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;
 }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226564&r1=226563&r2=226564&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 20 06:59:20 2015
@@ -4611,6 +4611,9 @@ TEST_F(FormatTest, AlwaysBreakBeforeMult
             format("NSString *const kString = @\"aaaa\"\n"
                    "\"bbbb\";",
                    Break));
+
+  Break.ColumnLimit = 0;
+  verifyFormat("const char *hello = \"hello llvm\";", Break);
 }
 
 TEST_F(FormatTest, AlignsPipes) {





More information about the cfe-commits mailing list