diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 27ad90c6879ab..1790a9df42b5d 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index 001c5bf5fcda1..1198329b7b5a8 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -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"