]> granicus.if.org Git - clang/commitdiff
clang-format: Fix alignment of trailing multiline columns.
authorDaniel Jasper <djasper@google.com>
Mon, 1 Feb 2016 11:20:55 +0000 (11:20 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 1 Feb 2016 11:20:55 +0000 (11:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259351 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d6e6ed2c2baa1cb76d2f66f40de87586e30c810e..0673dfb3aced3b0ea2fe02b532b0db445e8fb652 100644 (file)
@@ -372,16 +372,20 @@ void WhitespaceManager::alignTrailingComments() {
       unsigned CommentColumn = SourceMgr.getSpellingColumnNumber(
           Changes[i].OriginalWhitespaceRange.getEnd());
       for (unsigned j = i + 1; j != e; ++j) {
-        if (Changes[j].Kind != tok::comment) { // Skip over comments.
-          unsigned NextColumn = SourceMgr.getSpellingColumnNumber(
-              Changes[j].OriginalWhitespaceRange.getEnd());
-          // The start of the next token was previously aligned with the
-          // start of this comment.
-          WasAlignedWithStartOfNextLine =
-              CommentColumn == NextColumn ||
-              CommentColumn == NextColumn + Style.IndentWidth;
-          break;
-        }
+        if (Changes[j].Kind == tok::comment ||
+            Changes[j].Kind == tok::unknown)
+          // Skip over comments and unknown tokens. "unknown tokens are used for
+          // the continuation of multiline comments.
+          continue;
+
+        unsigned NextColumn = SourceMgr.getSpellingColumnNumber(
+            Changes[j].OriginalWhitespaceRange.getEnd());
+        // The start of the next token was previously aligned with the
+        // start of this comment.
+        WasAlignedWithStartOfNextLine =
+            CommentColumn == NextColumn ||
+            CommentColumn == NextColumn + Style.IndentWidth;
+        break;
       }
     }
     if (!Style.AlignTrailingComments || FollowsRBraceInColumn0) {
index 4e0d8d7acff656a791dc64457407eee96a93d0fa..057871b702110f26888ec9a9c18f1e478daa904d 100644 (file)
@@ -961,6 +961,14 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
             format("lineWith();   // comment\n"
                    "// at start\n"
                    "otherLine();"));
+  EXPECT_EQ("lineWith(); // comment\n"
+            "/*\n"
+            " * at start */\n"
+            "otherLine();",
+            format("lineWith();   // comment\n"
+                   "/*\n"
+                   " * at start */\n"
+                   "otherLine();"));
   EXPECT_EQ("lineWith(); // comment\n"
             "            // at start\n"
             "otherLine();",