Skip to content

clang-format: formatting is strange for lambdas with attributes in designated initializers #97013

Closed as not planned
@jacobsa

Description

@jacobsa

clang-format doesn't seem to correctly format lambdas with attributes, at least as part of designated initializers. For example, it wants this formatting for the following code:

SendCuratorRpcsRequest request = {
    .response_prototype = request.response_prototype,

    .choose_curators = [] [[clang::coro_wrapper]] ()
    -> k3::Gen<AddressAndChannel, void> { LOG(QFATAL) << "DO NOT SUBMIT"; },

    .rpc_timeout = some_long_expression + with_multiple_long_terms +
                   that_wraps_across_lines,
};

The formatting of the lambda is atypical, not aligning the second line with the rest of the lambda expression as is done with other expressions. I would expect something more like the following:

SendCuratorRpcsRequest request = {
    .response_prototype = request.response_prototype,

    .choose_curators = [] [[clang::coro_wrapper]] ()
                           -> k3::Gen<AddressAndChannel, void> {
                               LOG(QFATAL) << "DO NOT SUBMIT";
                        },

    .rpc_timeout = some_long_expression + with_multiple_long_terms +
                   that_wraps_across_lines,
};

or something closer to what you get if you remove the attribute but add a long capture list, with the second line at least indented:

SendCuratorRpcsRequest request = {
    .response_prototype = request.response_prototype,

    .choose_curators = [long_capture_list_here]()
        -> k3::Gen<AddressAndChannel, void> { LOG(QFATAL) << "DO NOT SUBMIT"; },

    .rpc_timeout = some_long_expression + with_multiple_long_terms +
                   that_wraps_across_lines,
};

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