From: Daniel Jasper <djasper@google.com>
Date: Tue, 29 Nov 2016 09:40:01 +0000 (+0000)
Subject: clang-format: Fix unnnecessary line break.
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ee02835dac4d0ebaeb92348ffc45711a50b8aad;p=clang

clang-format: Fix unnnecessary line break.

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
---

diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index e74515eb3b..2117a0ec93 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -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;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index e8e36abe68..a1614df6f3 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -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) {