clang-format: Fix behavior with comments before conditional expressions
authorDaniel Jasper <djasper@google.com>
Thu, 16 Oct 2014 09:10:11 +0000 (09:10 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 16 Oct 2014 09:10:11 +0000 (09:10 +0000)
Before:
  SomeFunction(aaaaaaaaaaaaaaaaa,
               // comment.
                   ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa
                                     : bbbbbbbbbbbbbbbbbbbb);

After:
  SomeFunction(aaaaaaaaaaaaaaaaa,
               // comment.
               ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa : bbbbbbbbbbbbbbbbbbbb);

llvm-svn: 219921

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

index a8e2c55..c83ec60 100644 (file)
@@ -1174,6 +1174,9 @@ private:
   }
 
   void parseConditionalExpr() {
+    while (Current && Current->isTrailingComment()) {
+      next();
+    }
     FormatToken *Start = Current;
     parse(prec::LogicalOr);
     if (!Current || !Current->is(tok::question))
index b195df4..aebfef6 100644 (file)
@@ -4060,6 +4060,12 @@ TEST_F(FormatTest, BreaksConditionalExpressions) {
       "        ?: aaaaaaaaaaaaaaa);\n"
       "}",
       NoBinPacking);
+
+  verifyFormat("SomeFunction(aaaaaaaaaaaaaaaaa,\n"
+               "             // comment.\n"
+               "             ccccccccccccccccccccccccccccccccccccccc\n"
+               "                 ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+               "                 : bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);");
 }
 
 TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) {