[clang] [clang-format] Option to insert spaces before the closing `*/` (PR #162105)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 28 01:14:56 PDT 2025
================
@@ -315,6 +315,19 @@ class AnnotatedLine;
/// A wrapper around a \c Token storing information about the
/// whitespace characters preceding it.
+
+// Describes the kind of a block comment.
+enum class CommentKind {
+ // A plain comment, i.e. /* ... */.
+ Plain,
+ // A comment that starts with /*! or /**.
+ Docstring,
+ // A comment that looks like a parameter, e.g. /*in*/.
+ Parameter,
+ // A comment that is a sentinel, e.g. /*FALLTHROUGH*/.
+ Sentinel,
----------------
Men-cotton wrote:
Regarding `CommentKind::Parameter`:
As suggested in https://github.com/llvm/llvm-project/pull/162105#discussion_r2414558403, I also agree that we should handle general comments and comments for parameter hints separately.
I've added a test case at https://github.com/llvm/llvm-project/pull/162105/files#diff-193d043bfe75f922dac78d66111b8a886a5b41e7cdd49a7582a0b382f584b75fR652-R665 that clearly demonstrates this separate handling.
Regarding `CommentKind::Sentinel`:
Currently, it is treated the same as `CommentKind::Plain`, inserting whitespace according to the existing options. This behavior can be seen in the tests at https://github.com/llvm/llvm-project/pull/162105/files#diff-193d043bfe75f922dac78d66111b8a886a5b41e7cdd49a7582a0b382f584b75fR408-R420 and https://github.com/llvm/llvm-project/pull/162105/files#diff-193d043bfe75f922dac78d66111b8a886a5b41e7cdd49a7582a0b382f584b75fR543-R555.
If necessary, we could add new options like `AfterOpeningSentinelComment` or `BeforeClosingSentinelComment`. If not, I plan to remove this kind from the enum and eliminate the corresponding detection logic.
I would appreciate your and @mydeveloperday's input on whether we should add these new options.
https://github.com/llvm/llvm-project/pull/162105
More information about the cfe-commits
mailing list