]> granicus.if.org Git - clang/commitdiff
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();

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

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

index ad390c23dcd62efcf6b65a2a93bcb8c10d8c74a3..0dd47fe4a99b18365eb6e21f4e5a0c7c95c2fe43 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 8435c94a0feb905c457e85ae9f27d93faafcd080..42cd89cc8b7c523677eb619ad6d1f094aba72a85 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)");