Hi klimek,

E.g. the second line in 

return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
           b; //

is indented 4 characters more than in

return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
       b;


http://llvm-reviews.chandlerc.com/D984

Files:
  tools/clang/lib/Format/TokenAnnotator.cpp
  tools/clang/unittests/Format/FormatTest.cpp

Index: tools/clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- tools/clang/lib/Format/TokenAnnotator.cpp
+++ tools/clang/lib/Format/TokenAnnotator.cpp
@@ -151,7 +151,7 @@
     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 @@
     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 @@
   }
 
   void next() {
-    if (Current != NULL)
+    if (Current)
+      Current = Current->Next;
+    while (Current && Current->isTrailingComment())
       Current = Current->Next;
   }
 
Index: tools/clang/unittests/Format/FormatTest.cpp
===================================================================
--- tools/clang/unittests/Format/FormatTest.cpp
+++ tools/clang/unittests/Format/FormatTest.cpp
@@ -2150,6 +2150,13 @@
                "} 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) {
Index: tools/clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- tools/clang/lib/Format/TokenAnnotator.cpp
+++ tools/clang/lib/Format/TokenAnnotator.cpp
@@ -151,7 +151,7 @@
     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 @@
     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 @@
   }
 
   void next() {
-    if (Current != NULL)
+    if (Current)
+      Current = Current->Next;
+    while (Current && Current->isTrailingComment())
       Current = Current->Next;
   }
 
Index: tools/clang/unittests/Format/FormatTest.cpp
===================================================================
--- tools/clang/unittests/Format/FormatTest.cpp
+++ tools/clang/unittests/Format/FormatTest.cpp
@@ -2150,6 +2150,13 @@
                "} 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) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to