Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6612,6 +6612,38 @@ the configuration (without a prefix: ``Auto``).
int a [5]; vs. int a[5];
int a [5][5]; vs. int a[5][5];

.. _SpaceInComments:

**SpaceInComments** (``Struct``) :versionbadge:`clang-format 21` :ref:`<SpaceInComments>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not handwritten, but generated by clang/doc/tools/dump_format_style.py, you need to make your documentation in Format.h.

Controls whitespace around block comment delimiters and parameter-style
inline comments. Each field accepts a ``CommentSpaceMode``: ``Leave``
(preserve existing spacing, the default), ``Always`` (insert a single space),
or ``Never`` (remove all spaces).

The available controls are:

``AfterOpeningComment``
Governs the space immediately after ``/*`` in regular block comments.
``BeforeClosingComment``
Governs the space before ``*/`` in regular block comments.
``AfterOpeningParamComment``
Governs the space after ``/*`` in parameter comments such as ``/*param=*/``.
``BeforeClosingParamComment``
Governs the space before ``*/`` in parameter comments.

.. code-block:: yaml
SpaceInComments:
BeforeClosingComment: Always
BeforeClosingParamComment: Never
.. code-block:: c++

// BeforeClosingComment: Always
auto Value = foo(/* comment */);
// BeforeClosingParamComment: Never
auto Number = foo(/*param=*/42);

.. _SpaceInEmptyBlock:

**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`<SpaceInEmptyBlock>`
Expand Down
31 changes: 31 additions & 0 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -4684,6 +4684,36 @@ struct FormatStyle {
/// \version 17
bool SpaceBeforeJsonColon;

/// Defines how clang-format should treat spaces around block comment
/// delimiters and specialized inline comments (such as parameter name
/// annotations). The default `Leave` mode preserves existing whitespace.
enum class CommentSpaceMode : int8_t {
/// Preserve existing whitespace, making no formatting changes.
Leave,
/// Ensure exactly one space is present.
Always,
/// Ensure no space is present.
Never,
};

/// Specifies spacing behavior for different block comment forms.
struct SpaceInCommentsOptions {
CommentSpaceMode AfterOpeningComment = CommentSpaceMode::Leave;
CommentSpaceMode BeforeClosingComment = CommentSpaceMode::Leave;
CommentSpaceMode AfterOpeningParamComment = CommentSpaceMode::Leave;
CommentSpaceMode BeforeClosingParamComment = CommentSpaceMode::Leave;

constexpr bool operator==(const SpaceInCommentsOptions &R) const {
return AfterOpeningComment == R.AfterOpeningComment &&
BeforeClosingComment == R.BeforeClosingComment &&
AfterOpeningParamComment == R.AfterOpeningParamComment &&
BeforeClosingParamComment == R.BeforeClosingParamComment;
}
};

/// Controls spacing inside block comments.
SpaceInCommentsOptions SpaceInComments;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort in the header according to the option name.


/// Different ways to put a space before opening parentheses.
enum SpaceBeforeParensStyle : int8_t {
/// This is **deprecated** and replaced by ``Custom`` below, with all
Expand Down Expand Up @@ -5612,6 +5642,7 @@ struct FormatStyle {
SpaceBeforeRangeBasedForLoopColon ==
R.SpaceBeforeRangeBasedForLoopColon &&
SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
SpaceInComments == R.SpaceInComments &&
SpaceInEmptyBraces == R.SpaceInEmptyBraces &&
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
SpacesInAngles == R.SpacesInAngles &&
Expand Down
Loading