From 9ee02835dac4d0ebaeb92348ffc45711a50b8aad Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 29 Nov 2016 09:40:01 +0000 Subject: [PATCH] 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 --- lib/Format/ContinuationIndenter.cpp | 3 ++- unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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) { -- 2.40.0