diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -555,7 +555,9 @@ // We never need a decoration when breaking just the trailing "*/" postfix. bool HasRemainingText = Offset < Content[LineIndex].size(); if (!HasRemainingText) { - LineLength -= Decoration.size(); + bool HasDecoration = Lines[LineIndex].ltrim().startswith(Decoration); + if (HasDecoration) + LineLength -= Decoration.size(); } } return LineLength; diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -2842,6 +2842,12 @@ "#define FOO_NODELOCAL 4 // Loopback\n\n" "} // namespace m\n", getLLVMStyleWithColumns(80))); + + // https://llvm.org/PR53441 + verifyFormat("/* */ //\n" + "int a; //\n"); + verifyFormat("/**/ //\n" + "int a; //\n"); } TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {