[clang] [llvm] clang-format reflow comments disable star: Fixes #58710 (PR #167146)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 8 07:22:43 PST 2025
https://github.com/bhanuponguru updated https://github.com/llvm/llvm-project/pull/167146
>From 49b5691690ac91de54e6b576597a085ec9efda46 Mon Sep 17 00:00:00 2001
From: bhanuponguru <cs23btech11046 at iith.ac.in>
Date: Fri, 7 Nov 2025 09:25:46 +0000
Subject: [PATCH 1/3] added a style for reflow comments to not add a star when
splitting blocked comments.
---
.clang-format | 3 +++
clang/include/clang/Format/Format.h | 13 +++++++++++++
clang/lib/Format/BreakableToken.cpp | 2 ++
clang/lib/Format/Format.cpp | 1 +
test.cpp | 4 ++++
5 files changed, 23 insertions(+)
create mode 100644 test.cpp
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/test.cpp b/test.cpp
new file mode 100644
index 0000000000000..cb7262ac27d61
--- /dev/null
+++ b/test.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()
+{
+}
\ No newline at end of file
>From 923c14ac0ca28b98feedaf13f0c5afca52daa3b2 Mon Sep 17 00:00:00 2001
From: Manojcs47 <cs23btech11047 at iith.ac.in>
Date: Sat, 8 Nov 2025 20:35:41 +0530
Subject: [PATCH 2/3] Added test cases
---
clang/test/Format/ReflowCommentsNoStar.cpp | 2 ++
clang/test/Format/ReflowCommentsNoStarExpected.cpp | 4 ++++
clang/test/Format/ReflowCommentsNoStarInput.cpp | 3 +++
3 files changed, 9 insertions(+)
create mode 100644 clang/test/Format/ReflowCommentsNoStar.cpp
create mode 100644 clang/test/Format/ReflowCommentsNoStarExpected.cpp
create mode 100644 clang/test/Format/ReflowCommentsNoStarInput.cpp
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() {}
>From 0daa7af6bb91e0e3e0f10274ffe7d80b1b5493df Mon Sep 17 00:00:00 2001
From: Manojcs47 <cs23btech11047 at iith.ac.in>
Date: Sat, 8 Nov 2025 20:40:46 +0530
Subject: [PATCH 3/3] removed test file
---
test.cpp | 4 ----
1 file changed, 4 deletions(-)
delete mode 100644 test.cpp
diff --git a/test.cpp b/test.cpp
deleted file mode 100644
index cb7262ac27d61..0000000000000
--- a/test.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-/* 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()
-{
-}
\ No newline at end of file
More information about the llvm-commits
mailing list