]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect line breaks after forced operator wraps.
authorDaniel Jasper <djasper@google.com>
Wed, 1 Feb 2017 23:27:37 +0000 (23:27 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 1 Feb 2017 23:27:37 +0000 (23:27 +0000)
Before:
  bool x = aaaaa //
           ||
           bbbbb
           //
           || cccc;

After:
  bool x = aaaaa //
           || bbbbb
           //
           || cccc;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293839 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 176f4674aaba71ead6dcc1e0619697037b49e204..a7eb82ad56fde392f05939c0490f4423ed3430b5 100644 (file)
@@ -420,7 +420,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
       P->getPrecedence() != prec::Assignment &&
       P->getPrecedence() != prec::Relational) {
     bool BreakBeforeOperator =
-        P->is(tok::lessless) ||
+        P->MustBreakBefore || P->is(tok::lessless) ||
         (P->is(TT_BinaryOperator) &&
          Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) ||
         (P->is(TT_ConditionalExpr) && Style.BreakBeforeTernaryOperators);
index 390dd203704506beaf1e83d651f6ea8360bbe4c0..cb0d7b32972b364d6ea2ca03e962702103591561 100644 (file)
@@ -4151,6 +4151,15 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) {
                Style);
 }
 
+TEST_F(FormatTest, EnforcedOperatorWraps) {
+  // Here we'd like to wrap after the || operators, but a comment is forcing an
+  // earlier wrap.
+  verifyFormat("bool x = aaaaa //\n"
+               "         || bbbbb\n"
+               "         //\n"
+               "         || cccc;");
+}
+
 TEST_F(FormatTest, NoOperandAlignment) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignOperands = false;