clang-format: Less eagerly try to keep label-value pairs on a line.
authorDaniel Jasper <djasper@google.com>
Thu, 22 Dec 2016 12:37:06 +0000 (12:37 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 22 Dec 2016 12:37:06 +0000 (12:37 +0000)
Before:
  string v =
      StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ", SomeFunction(aaaaaaaaaaaa,
                                                           aaaaaaaaaaaaaaa),
             bbbbbbbbbbbbbbbbbbbbbbb);

After:
  string v = StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ",
                    SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaa),
                    bbbbbbbbbbbbbbbbbbbbbbb);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290337 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 7f5730615944900ed4ffb6c29b9a5122c50c50e0..cf6373f4565737ab5371ab50fa90dfbec0cb799c 100644 (file)
@@ -2001,7 +2001,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
       Left.Previous->isLabelString() &&
       (Left.NextOperator || Left.OperatorIndex != 0))
-    return 100;
+    return 45;
   if (Right.is(tok::plus) && Left.isLabelString() &&
       (Right.NextOperator || Right.OperatorIndex != 0))
     return 25;
index 09b85357d152e9024c68994af3d7acaa2da283bd..6f9df680eef5b2a2acd4f391da725bb785033fff 100644 (file)
@@ -5220,6 +5220,10 @@ TEST_F(FormatTest, KeepStringLabelValuePairsOnALine) {
   verifyFormat("string v = StrCat(\"aaaaaaaaaaaa: \" +\n"
                "                  (aaaaaaa + aaaaa));",
                getLLVMStyleWithColumns(40));
+  verifyFormat(
+      "string v = StrCat(\"aaaaaaaaaaaaaaaaaaaaaaaaaaa: \",\n"
+      "                  SomeFunction(aaaaaaaaaaaa, aaaaaaaa.aaaaaaa),\n"
+      "                  bbbbbbbbbbbbbbbbbbbbbbb);");
 }
 
 TEST_F(FormatTest, UnderstandsEquals) {