[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
Tue Oct 28 15:02:05 PDT 2025


================
@@ -332,6 +332,397 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
   verifyNoCrash(StringRef("/*\\\0\n/", 6));
 }
 
+TEST_F(FormatTestComments, InsertsSpaceAfterOpeningBlockComment) {
+  FormatStyle Style = getLLVMStyle();
+  Style.SpaceInComments.AfterOpeningComment =
+      FormatStyle::CommentSpaceMode::Always;
+
+  verifyFormat("foo(/* comment */);", "foo(/*comment */);", Style);
+  verifyFormat("/* comment */", "/*comment */", Style);
+  verifyFormat("/* comment before code */\n"
+               "int x;",
+               "/*comment before code */\n"
+               "int x;",
+               Style);
+  verifyFormat("/* \n"
+               "comment */",
+               "/*\n"
+               "comment */",
+               Style);
+  verifyFormat("/* \ncomment */\n"
+               "int x;",
+               "/*\ncomment */\n"
+               "int x;",
+               Style);
+  verifyFormat("/* \n"
+               "comment line\n"
+               "*/",
+               "/*\n"
+               "comment line\n"
+               "*/",
+               Style);
+  verifyFormat("/* \n"
+               " * comment star\n"
+               "*/",
+               "/*\n"
+               " * comment star\n"
+               "*/",
+               Style);
+  verifyFormat("/* comment line\n"
+               "next */",
+               "/*comment line\n"
+               "next */",
+               Style);
+  verifyFormat("/* */", "/* */", Style);
+  verifyFormat("/*\n*/", "/*\n*/", Style);
----------------
HazardyKnusperkeks wrote:

```suggestion
  verifyFormat("/*\n"
  "*/", "/*\n"
  "*/", Style);
```
Please break after each `\n` in strings.

https://github.com/llvm/llvm-project/pull/162105


More information about the cfe-commits mailing list