Skip to content

clang-format: Allow empty records on a single line #166632

@daggerbot

Description

@daggerbot

Feel free to close this if this is already possible and I just failed to figure out how.

There doesn't appear to be a way to accomplish this with clang-format:

// Break before braces after class/struct/union:
struct Foo
{
  int x;
};

// AND allow empty class/struct/union on a single line:
struct Foo {};

If we set BraceWrapping: AfterStruct: true and BraceWrapping: SplitEmptyRecord: false, we instead get this:

struct Foo
{};

My proposal would be to add a bool AllowEmptyRecordsOnASingleLine option that handles this case similarly to the AllowShortEnumsOnASingleLine option. If others think this would be an acceptable enhancement, I can look into implementing it myself, but I thought I'd request feedback before I put in the work.

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