Skip to content

Commit

Permalink
[clang-format] Fix a bug in aligning trailing comments (#67221)
Browse files Browse the repository at this point in the history
Fixes #67116.
  • Loading branch information
owenca committed Sep 25, 2023
1 parent 5f17fcf commit d3f8c88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ void WhitespaceManager::alignTrailingComments() {
const int OriginalSpaces =
C.OriginalWhitespaceRange.getEnd().getRawEncoding() -
C.OriginalWhitespaceRange.getBegin().getRawEncoding() -
C.Tok->NewlinesBefore;
C.Tok->LastNewlineOffset;
assert(OriginalSpaces >= 0);
const auto RestoredLineLength =
C.StartOfTokenColumn + C.TokenLength + OriginalSpaces;
Expand Down
6 changes: 6 additions & 0 deletions clang/unittests/Format/FormatTestComments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,12 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
"}",
Style);

Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
verifyNoChange("#define FOO \\\n"
" /* foo(); */ \\\n"
" bar();",
Style);

// Allow to keep 2 empty lines
Style.MaxEmptyLinesToKeep = 2;
EXPECT_EQ("// do not touch\n"
Expand Down

0 comments on commit d3f8c88

Please sign in to comment.