Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jacobsa opened this issue Jun 28, 2024 · 1 comment
Labels
clang-format duplicate Resolved as duplicate

Comments

@jacobsa
Copy link
Contributor

jacobsa commented Jun 28, 2024

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,
};
@rymiel
Copy link
Member

rymiel commented Jun 28, 2024

This has already been fixed in d9593c1. The fix will be present in clang-format 19. Duplicate of #94181

@rymiel rymiel closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
@rymiel rymiel added the duplicate Resolved as duplicate label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

2 participants