]> granicus.if.org Git - clang/commitdiff
clang-format: Fix fake parentheses placement with comments.
authorDaniel Jasper <djasper@google.com>
Wed, 3 Dec 2014 14:02:59 +0000 (14:02 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 3 Dec 2014 14:02:59 +0000 (14:02 +0000)
Before:
  return (a > b
          // comment1
      // comment2
      || c);

After:
  return (a > b
      // comment1
      // comment2
      || c);

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

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

index 3b04e49ba513207febcc512b22e93c735327d714..9b215dcd473bc7783f6919f8bd31a66816ee5506 100644 (file)
@@ -1217,7 +1217,7 @@ private:
       Start->StartsBinaryExpression = true;
     if (Current) {
       FormatToken *Previous = Current->Previous;
-      if (Previous->is(tok::comment) && Previous->Previous)
+      while (Previous->is(tok::comment) && Previous->Previous)
         Previous = Previous->Previous;
       ++Previous->FakeRParens;
       if (Precedence > prec::Unknown)
index 148c2f98ff749407f483313e694ef86e7b53342e..ea5f67ca49d6483d3b6a8cec10e0659290af0a67 100644 (file)
@@ -3337,6 +3337,13 @@ TEST_F(FormatTest, NoOperandAlignment) {
                "    + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
                "        * cccccccccccccccccccccccccccccccccccc;",
                Style);
+
+  Style.AlignAfterOpenBracket = false;
+  verifyFormat("return (a > b\n"
+               "    // comment1\n"
+               "    // comment2\n"
+               "    || c);",
+               Style);
 }
 
 TEST_F(FormatTest, BreakingBeforeNonAssigmentOperators) {