diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 24 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 8 |
2 files changed, 22 insertions, 10 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index d6e6ed2c2ba..0673dfb3ace 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -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) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 4e0d8d7acff..057871b7021 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -962,6 +962,14 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) { "// 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();", format("lineWith(); // comment\n" |