]> granicus.if.org Git - clang/commitdiff
clang-format: Correctly apply wrap before multi-line RHS rule to
authorDaniel Jasper <djasper@google.com>
Tue, 1 Mar 2016 04:19:59 +0000 (04:19 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 1 Mar 2016 04:19:59 +0000 (04:19 +0000)
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

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

index b9afe117bc134d470bb2ea061415d78d5978e87b..4e5a29426a27f14a17ab9a3a470b24c0d199b867 100644 (file)
@@ -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 =
index b00b895c5f802156ffe4b31c4d9191a27d84b174..164909f8688d0dc5a4afc32317c6edc109540012 100644 (file)
@@ -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) {