From: Daniel Jasper Date: Tue, 1 Mar 2016 04:19:59 +0000 (+0000) Subject: clang-format: Correctly apply wrap before multi-line RHS rule to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1414490fdffa2548f4bad963b6c4693bf8a37354;p=clang clang-format: Correctly apply wrap before multi-line RHS rule to ternary expressions. Before: return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaa : bbbbbbbbbbbbbbb + cccccccccccccccc; After: return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaa : bbbbbbbbbbbbbbb + cccccccccccccccc; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262293 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index b9afe117bc..4e5a29426a 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -847,7 +847,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, // there is a line-break right after the operator. // Exclude relational operators, as there, it is always more desirable to // have the LHS 'left' of the RHS. - if (Previous && Previous->getPrecedence() > prec::Assignment && + if (Previous && Previous->getPrecedence() != prec::Assignment && Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Previous->getPrecedence() != prec::Relational) { bool BreakBeforeOperator = diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b00b895c5f..164909f868 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4708,6 +4708,10 @@ TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { " /*bbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :\n" " ccccccccccccccccccccccccccc;", Style); + verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?\n" + " aaaaa :\n" + " bbbbbbbbbbbbbbb + cccccccccccccccc;", + Style); } TEST_F(FormatTest, DeclarationsOfMultipleVariables) {