[clang] [clang-format] Option to insert spaces before the closing `*/` (PR #162105)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 27 13:22:18 PDT 2025
================
@@ -332,6 +332,181 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
verifyNoCrash(StringRef("/*\\\0\n/", 6));
}
+TEST_F(FormatTestComments, InsertsSpaceAfterOpeningBlockComment) {
+ FormatStyle Style = getLLVMStyle();
+ Style.SpaceInComments.AfterOpeningComment =
+ FormatStyle::CommentSpaceMode::Always;
+ Style.ReflowComments = FormatStyle::RCS_Never;
+
+ verifyFormat("foo(/* comment */);", "foo(/*comment */);", Style);
+ verifyFormat("foo(/* Logger=*/nullptr);", "foo(/*Logger=*/nullptr);", Style);
+ verifyFormat("/* comment */", "/*comment */", Style);
+ verifyFormat("/* comment before code */\nint x;",
+ "/*comment before code */\nint x;", Style);
+ verifyFormat("/* \ncomment */", "/*\ncomment */", Style);
+ verifyFormat("/* \ncomment */\nint x;", "/*\ncomment */\nint x;", Style);
+ verifyFormat("/* \ncomment line\n*/", "/*\ncomment line\n*/", Style);
+ verifyFormat("/* \n * comment star\n*/", "/*\n * comment star\n*/", Style);
+ verifyFormat("/* comment line\nnext */", "/*comment line\nnext */", Style);
+ EXPECT_EQ("/*\n*/", format("/*\n*/", Style));
----------------
HazardyKnusperkeks wrote:
That's one of the reasons why there is the three argument variant (you didn't count the `Style` argument). So yeah, exactly that.
https://github.com/llvm/llvm-project/pull/162105
More information about the cfe-commits
mailing list