Skip to content

Commit d3f8c88

Browse files
authored
[clang-format] Fix a bug in aligning trailing comments (llvm#67221)
Fixes llvm#67116.
1 parent 5f17fcf commit d3f8c88

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ void WhitespaceManager::alignTrailingComments() {
10621062
const int OriginalSpaces =
10631063
C.OriginalWhitespaceRange.getEnd().getRawEncoding() -
10641064
C.OriginalWhitespaceRange.getBegin().getRawEncoding() -
1065-
C.Tok->NewlinesBefore;
1065+
C.Tok->LastNewlineOffset;
10661066
assert(OriginalSpaces >= 0);
10671067
const auto RestoredLineLength =
10681068
C.StartOfTokenColumn + C.TokenLength + OriginalSpaces;

clang/unittests/Format/FormatTestComments.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,12 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
30533053
"}",
30543054
Style);
30553055

3056+
Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
3057+
verifyNoChange("#define FOO \\\n"
3058+
" /* foo(); */ \\\n"
3059+
" bar();",
3060+
Style);
3061+
30563062
// Allow to keep 2 empty lines
30573063
Style.MaxEmptyLinesToKeep = 2;
30583064
EXPECT_EQ("// do not touch\n"

0 commit comments

Comments
 (0)