[clang] f771d08 - [clang-format] Fix a bug in `ReflowComments: Always` (#146202)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 28 15:23:03 PDT 2025


Author: Owen Pan
Date: 2025-06-28T15:23:00-07:00
New Revision: f771d08a24762dada69bf426016f5fd1cf83a437

URL: https://github.com/llvm/llvm-project/commit/f771d08a24762dada69bf426016f5fd1cf83a437
DIFF: https://github.com/llvm/llvm-project/commit/f771d08a24762dada69bf426016f5fd1cf83a437.diff

LOG: [clang-format] Fix a bug in `ReflowComments: Always` (#146202)

Fixes #39150

Added: 
    

Modified: 
    clang/lib/Format/BreakableToken.cpp
    clang/unittests/Format/FormatTestComments.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 5317c05f3a460..def0d73e77539 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -158,8 +158,7 @@ getCommentSplit(StringRef Text, unsigned ContentStartColumn,
       return BreakableToken::Split(StringRef::npos, 0);
     StringRef BeforeCut = Text.substr(0, SpaceOffset).rtrim(Blanks);
     StringRef AfterCut = Text.substr(SpaceOffset);
-    // Don't trim the leading blanks if it would create a */ after the break.
-    if (!DecorationEndsWithStar || AfterCut.size() <= 1 || AfterCut[1] != '/')
+    if (!DecorationEndsWithStar)
       AfterCut = AfterCut.ltrim(Blanks);
     return BreakableToken::Split(BeforeCut.size(),
                                  AfterCut.begin() - BeforeCut.end());

diff  --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 5eefd767706a3..a16fbffb76270 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -2486,7 +2486,7 @@ TEST_F(FormatTestComments, BlockComments) {
   EXPECT_EQ("/*\n"
             "**\n"
             "* aaaaaa\n"
-            "*aaaaaa\n"
+            "* aaaaaa\n"
             "*/",
             format("/*\n"
                    "**\n"


        


More information about the cfe-commits mailing list