]> granicus.if.org Git - clang/commitdiff
clang-format: Improve handling of comments in binary expressions.
authorDaniel Jasper <djasper@google.com>
Tue, 11 Nov 2014 23:04:51 +0000 (23:04 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 11 Nov 2014 23:04:51 +0000 (23:04 +0000)
Before:
  b = a &&
      // Comment
      b.c &&
      d;

After:
  b = a &&
      // Comment
      b.c && d;

This fixes llvm.org/PR21535.

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 715cbf0a48339c035412842289f3a0300317c808..8ec8f58d14732c5374de76933b28d16727f33c70 100644 (file)
@@ -1149,8 +1149,7 @@ public:
           Current->OperatorIndex = OperatorIndex;
           ++OperatorIndex;
         }
-
-        next(/*SkipPastLeadingComments=*/false);
+        next(/*SkipPastLeadingComments=*/Precedence > 0);
       }
     }
   }
index 1f95a89893d559958d9b52cacf2629de09d5a73a..37c3c0e7528a90bd774b7d9c4b00d6cda9005462 100644 (file)
@@ -3118,6 +3118,9 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat("if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
                "     bbbbbbbbbbbbbbbbbb) && // aaaaaaaaaaaaaaaa\n"
                "    cccccc) {\n}");
+  verifyFormat("b = a &&\n"
+               "    // Comment\n"
+               "    b.c && d;");
 
   // If the LHS of a comparison is not a binary expression itself, the
   // additional linebreak confuses many people.