diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp --- a/clang/lib/AST/RawCommentList.cpp +++ b/clang/lib/AST/RawCommentList.cpp @@ -431,7 +431,7 @@ }; auto DropTrailingNewLines = [](std::string &Str) { - while (Str.back() == '\n') + while (!Str.empty() && Str.back() == '\n') Str.pop_back(); }; diff --git a/clang/unittests/AST/CommentTextTest.cpp b/clang/unittests/AST/CommentTextTest.cpp --- a/clang/unittests/AST/CommentTextTest.cpp +++ b/clang/unittests/AST/CommentTextTest.cpp @@ -124,4 +124,10 @@ // clang-format on } +TEST_F(CommentTextTest, WorksWithEmptyBlockComments) { + auto ExpectedOutput = ""; + auto Formatted = formatComment(R"(/* */)"); + EXPECT_EQ(ExpectedOutput, Formatted); +} + } // namespace clang