Skip to content

Conversation

@bhanuponguru
Copy link

Created a new style "ReflowCommentsNoStar: true|false", to disable placing a star when blocked comments are split.

Fixes #58710

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2025

@llvm/pr-subscribers-clang-format

Author: bhanuponguru (bhanuponguru)

Changes

Created a new style "ReflowCommentsNoStar: true|false", to disable placing a star when blocked comments are split.

Fixes #58710


Full diff: https://github.com/llvm/llvm-project/pull/167146.diff

7 Files Affected:

  • (modified) .clang-format (+3)
  • (modified) clang/include/clang/Format/Format.h (+13)
  • (modified) clang/lib/Format/BreakableToken.cpp (+2)
  • (modified) clang/lib/Format/Format.cpp (+1)
  • (added) clang/test/Format/ReflowCommentsNoStar.cpp (+2)
  • (added) clang/test/Format/ReflowCommentsNoStarExpected.cpp (+4)
  • (added) clang/test/Format/ReflowCommentsNoStarInput.cpp (+3)
diff --git a/.clang-format b/.clang-format
index ecb44bfabd9aa..609dc68c8cd98 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,2 +1,5 @@
 BasedOnStyle: LLVM
 LineEnding: LF
+ColumnLimit: 80
+ReflowComments: true
+ReflowCommentsNoStar: true
\ No newline at end of file
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index f246defc1fe81..2167544c0bd98 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4240,6 +4240,19 @@ struct FormatStyle {
   /// \version 3.8
   ReflowCommentsStyle ReflowComments;
 
+  /// If reflow comments is enabled, dont include * in the formatted block comment.
+    /// \code
+    ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
+    ///    // information
+    ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
+    ///     information */
+    ///    /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
+    ///     information and a misaligned second line */
+    /// \endcode
+
+  /// \version 22
+  bool ReflowCommentsNoStar;
+
   /// Remove optional braces of control statements (``if``, ``else``, ``for``,
   /// and ``while``) in C++ according to the LLVM coding style.
   /// \warning
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 994a427517ffc..677aa2026e272 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -506,6 +506,8 @@ BreakableBlockComment::BreakableBlockComment(
   }
 
   Decoration = "* ";
+  if (Style.ReflowCommentsNoStar)
+    Decoration = "";
   if (Lines.size() == 1 && !FirstInLine) {
     // Comments for which FirstInLine is false can start on arbitrary column,
     // and available horizontal space can be too small to align consecutive
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dd14fcd72922f..f0bfa60fd76b2 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1275,6 +1275,7 @@ template <> struct MappingTraits<FormatStyle> {
     IO.mapOptional("RawStringFormats", Style.RawStringFormats);
     IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment);
     IO.mapOptional("ReflowComments", Style.ReflowComments);
+    IO.mapOptional("ReflowCommentsNoStar", Style.ReflowCommentsNoStar);
     IO.mapOptional("RemoveBracesLLVM", Style.RemoveBracesLLVM);
     IO.mapOptional("RemoveEmptyLinesInUnwrappedLines",
                    Style.RemoveEmptyLinesInUnwrappedLines);
diff --git a/clang/test/Format/ReflowCommentsNoStar.cpp b/clang/test/Format/ReflowCommentsNoStar.cpp
new file mode 100644
index 0000000000000..d1ce8506c818f
--- /dev/null
+++ b/clang/test/Format/ReflowCommentsNoStar.cpp
@@ -0,0 +1,2 @@
+// RUN: clang-format -style="{ColumnLimit: 80, ReflowComments: true, ReflowCommentsNoStar: true}" %S/ReflowCommentsNoStarInput.cpp > %t
+// RUN: diff %t %S/ReflowCommentsNoStarExpected.cpp
\ No newline at end of file
diff --git a/clang/test/Format/ReflowCommentsNoStarExpected.cpp b/clang/test/Format/ReflowCommentsNoStarExpected.cpp
new file mode 100644
index 0000000000000..35ba5e919f820
--- /dev/null
+++ b/clang/test/Format/ReflowCommentsNoStarExpected.cpp
@@ -0,0 +1,4 @@
+/* erfdfdfdfdfdfd fd fdfd fd fd fd fd fd fd fd fd fd fd fd fd fd fdf df df df df
+   df df df df df df df fd f */
+
+void func() {}
diff --git a/clang/test/Format/ReflowCommentsNoStarInput.cpp b/clang/test/Format/ReflowCommentsNoStarInput.cpp
new file mode 100644
index 0000000000000..5ec0e32298337
--- /dev/null
+++ b/clang/test/Format/ReflowCommentsNoStarInput.cpp
@@ -0,0 +1,3 @@
+/* erfdfdfdfdfdfd fd fdfd fd fd fd fd fd fd fd fd fd fd fd fd fd fdf df df df df df df df df df df df fd f */
+
+void func() {}

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang/test/Format/ReflowCommentsNoStar.cpp clang/test/Format/ReflowCommentsNoStarExpected.cpp clang/test/Format/ReflowCommentsNoStarInput.cpp clang/include/clang/Format/Format.h clang/lib/Format/BreakableToken.cpp clang/lib/Format/Format.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 1c3050ec9..4de1a9f40 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4250,15 +4250,19 @@ struct FormatStyle {
   /// \version 3.8
   ReflowCommentsStyle ReflowComments;
 
-  /// If reflow comments is enabled, dont include * in the formatted block comment.
-    /// \code
-    ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
-    ///    // information
-    ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
-    ///     information */
-    ///    /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
-    ///     information and a misaligned second line */
-    /// \endcode
+  /// If reflow comments is enabled, dont include * in the formatted block
+  /// comment.
+  /// \code
+  ///    // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty
+  ///    of
+  ///    // information
+  ///    /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with
+  ///    plenty of
+  ///     information */
+  ///    /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with
+  ///    plenty of
+  ///     information and a misaligned second line */
+  /// \endcode
 
   /// \version 22
   bool ReflowCommentsNoStar;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add clang-format setting to disable "*" being added when ReflowComments is used with /* */ comments

3 participants