From 04b4e10873f6728f382ce2e2aa71aa10831c101f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 1 Mar 2016 04:19:59 +0000 Subject: [PATCH] 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; llvm-svn: 262293 --- clang/lib/Format/ContinuationIndenter.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index b9afe11..4e5a294 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index b00b895..164909f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) { -- 2.7.4