Fix indentation problem for comments in call chains
authorDaniel Jasper <djasper@google.com>
Thu, 11 Jul 2013 13:48:16 +0000 (13:48 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 11 Jul 2013 13:48:16 +0000 (13:48 +0000)
Before:
SomeObject
    // Calling someFunction on SomeObject
        .someFunction();

After:
SomeObject
    // Calling someFunction on SomeObject
    .someFunction();

llvm-svn: 186085

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

index ad390c2..0dd47fe 100644 (file)
@@ -589,7 +589,8 @@ private:
                                       State.Column, Line.InPPDirective);
       }
 
-      State.Stack.back().LastSpace = State.Column;
+      if (!Current.isTrailingComment())
+        State.Stack.back().LastSpace = State.Column;
       if (Current.isOneOf(tok::arrow, tok::period) &&
           Current.Type != TT_DesignatedInitializerPeriod)
         State.Stack.back().LastSpace += Current.CodePointCount;
index 8435c94..42cd89c 100644 (file)
@@ -576,6 +576,9 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
   verifyFormat("void f() {\n"
                "  // Doesn't do anything\n"
                "}");
+  verifyFormat("SomeObject\n"
+               "    // Calling someFunction on SomeObject\n"
+               "    .someFunction();");
   verifyFormat("void f(int i,  // some comment (probably for i)\n"
                "       int j,  // some comment (probably for j)\n"
                "       int k); // some comment (probably for k)");