Skip to content

[feature request] [clang-format] Put brace on new line in constructor after multi-line member initializer listΒ #79132

@flyx

Description

@flyx

To separate a constructor's member initializer list from its body, I'd like to use this style:

// short, all in one line, currently possible.
MyClass::MyClass(int val): val{val} {
    // body
}

// member initializers don't fit on one line.
// separate initializers from body by putting
// brace on new line, currently not possible.
MyClass::MyClass(int someValue, int anotherValue):
    some_value{some_value}, another_value{another_value}
{
    // body
}

// multi-line arguments, but inline initializers.
// currently possible.
MyClass::MyClass(
    int argumentWithVeryDetailedName
): val{argumentWithVeryDetailedName} {
    // body
}

// both multi-line arguments and multi-line initializers.
// as before, the brace on a new line is not possible.
MyClass::MyCLass(
    int argumentWithVeryDetailedName
):
    fieldWithVeryDetailedName{argumentWithVeryDetailedName}
{
    // body
}

So, the { should be on a new line if and only the member initializers are not inline. Currently, clang-format always puts it at the end of the line of the last initializer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-formatenhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions