Fix aligning of comments that are at the start of the line.

Now correctly leaves:
f(); // comment
// comment
g(); // comment
... alone if the middle comment was aligned with g() before formatting.

llvm-svn: 182605
This commit is contained in:
Manuel Klimek 2013-05-23 19:54:43 +00:00
parent bfe2e5f778
commit b27375fcd7
2 changed files with 11 additions and 3 deletions

View File

@ -170,9 +170,10 @@ void WhitespaceManager::alignTrailingComments() {
MinColumn = std::max(MinColumn, ChangeMinColumn);
MaxColumn = std::min(MaxColumn, ChangeMaxColumn);
}
BreakBeforeNext =
(i == 0) || (Changes[i].NewlinesBefore > 1) ||
(Changes[i].NewlinesBefore == 1 && !Changes[i - 1].IsTrailingComment);
BreakBeforeNext = (i == 0) || (Changes[i].NewlinesBefore > 1) ||
(Changes[i].NewlinesBefore == 1 &&
!Changes[i - 1].IsTrailingComment) ||
WasAlignedWithStartOfNextLine;
Newlines = 0;
}
}

View File

@ -650,6 +650,13 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
format("lineWith(); // comment\n"
" // at start\n"
"otherLine();"));
EXPECT_EQ("lineWith(); // comment\n"
"// at start\n"
"otherLine(); // comment",
format("lineWith(); // comment\n"
"// at start\n"
"otherLine(); // comment"));
}
TEST_F(FormatTest, CanFormatCommentsLocally) {