[clang] [clang-format] Fix a bug in `ReflowComments: Always` (PR #146202)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 28 00:31:57 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->39150
---
Full diff: https://github.com/llvm/llvm-project/pull/146202.diff
2 Files Affected:
- (modified) clang/lib/Format/BreakableToken.cpp (+1-2)
- (modified) clang/unittests/Format/FormatTestComments.cpp (+1-1)
``````````diff
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"
``````````
</details>
https://github.com/llvm/llvm-project/pull/146202
More information about the cfe-commits
mailing list