]> granicus.if.org Git - clang/commitdiff
Fix a problem in ExpressionParser leading to trailing comments affecting indentation...
authorAlexander Kornienko <alexfh@google.com>
Mon, 17 Jun 2013 13:19:53 +0000 (13:19 +0000)
committerAlexander Kornienko <alexfh@google.com>
Mon, 17 Jun 2013 13:19:53 +0000 (13:19 +0000)
Summary:
E.g. the second line in

return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
           b; //

is indented 4 characters more than in

return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
       b;

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D984

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

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

index 85c5a36a0a719f1824f98c975db3b3efdfef18b7..c6b491914b3c0d7fe69e0ec2d972f5a74a0f1bea 100644 (file)
@@ -151,7 +151,7 @@ private:
     if (!CurrentToken)
       return false;
 
-    // A '[' could be an index subscript (after an indentifier or after
+    // A '[' could be an index subscript (after an identifier or after
     // ')' or ']'), it could be the start of an Objective-C method
     // expression, or it could the the start of an Objective-C array literal.
     FormatToken *Left = CurrentToken->Previous;
@@ -792,11 +792,6 @@ public:
     if (Precedence > prec::PointerToMember || Current == NULL)
       return;
 
-    // Eagerly consume trailing comments.
-    while (Current && Current->isTrailingComment()) {
-      next();
-    }
-
     FormatToken *Start = Current;
     bool OperatorFound = false;
 
@@ -862,7 +857,9 @@ private:
   }
 
   void next() {
-    if (Current != NULL)
+    if (Current)
+      Current = Current->Next;
+    while (Current && Current->isTrailingComment())
       Current = Current->Next;
   }
 
index a26bf607214638613c5f7d9758a50be6a1bb6821..8454af32ed525279b8612d9a64ccbd2fde31323a 100644 (file)
@@ -2150,6 +2150,13 @@ TEST_F(FormatTest, ExpressionIndentation) {
                "} else if (aaaaa && bbbbb > // break\n"
                "                        ccccc) {\n"
                "}");
+
+  // Presence of a trailing comment used to change indentation of b.
+  verifyFormat("return aaaaaaaaaaaaaaaaaaa +\n"
+               "       b;\n"
+               "return aaaaaaaaaaaaaaaaaaa +\n"
+               "       b; //",
+               getLLVMStyleWithColumns(30));
 }
 
 TEST_F(FormatTest, ConstructorInitializers) {