]> granicus.if.org Git - clang/commitdiff
clang-format: Fix unnnecessary line break.
authorDaniel Jasper <djasper@google.com>
Tue, 29 Nov 2016 09:40:01 +0000 (09:40 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 29 Nov 2016 09:40:01 +0000 (09:40 +0000)
Before:
  aaaaaaaaaa(aaaa(aaaa,
  aaaa), //
     aaaa,
             aaaaa);

After:
  aaaaaaaaaa(aaaa(aaaa,
  aaaa), //
     aaaa, aaaaa);

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

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

index e74515eb3b3424503a0df4a5cf5cd81edffa8532..2117a0ec93c3482906b067c69900e0bd67245981 100644 (file)
@@ -523,7 +523,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
           Style.ContinuationIndentWidth;
   }
 
-  if ((Previous.isOneOf(tok::comma, tok::semi) &&
+  if ((PreviousNonComment &&
+       PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
        !State.Stack.back().AvoidBinPacking) ||
       Previous.is(TT_BinaryOperator))
     State.Stack.back().BreakBeforeParameter = false;
index e8e36abe681a39508c2c816447e62317288d5c0f..a1614df6f3806b52be7f359c526ce0c6b0035b4f 100644 (file)
@@ -1137,6 +1137,12 @@ TEST_F(FormatTest, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {
             format("SomeFunction(a,     // comment\n"
                    "          b,\n"
                    "      c); // comment"));
+  EXPECT_EQ("aaaaaaaaaa(aaaa(aaaa,\n"
+            "                aaaa), //\n"
+            "           aaaa, bbbbb);",
+            format("aaaaaaaaaa(aaaa(aaaa,\n"
+                   "aaaa), //\n"
+                   "aaaa, bbbbb);"));
 }
 
 TEST_F(FormatTest, RemovesTrailingWhitespaceOfComments) {