Skip to content

[clang-format] Incorrect Formatting Between clang-format off and clang-format on #146317

Open
@rocfu

Description

@rocfu

Here is a snippet of isolated and formatted C++ code, but in my configuration, it causes the section between "clang-format off" and "clang-format on" to be formatted. It seems that the SeparateDefinitionBlocks option doesn't prevent formatting and still triggers it before the // clang-format on section.

// clang-format off
void function()
{

}
// clang-format on

The formatting result adds an extra line between the function and the // clang-format on comment:

// clang-format off
void function()
{

}

// clang-format on

My environment:

  • clang-format version 17.0.6 and version 18.1.4

.clang-format configuration:

Language:     Cpp
SeparateDefinitionBlocks: Always

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions