llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.51k stars 11.3k forks source link

[clang-format] strange formatting for trailing member function call after aggregate initialization #97240

Open jacobsa opened 1 month ago

jacobsa commented 1 month ago

clang-format provides strange formatting for an expression that involves a member function call on an rvalue constructed with aggregate initialization. For example:

return MyStruct{
    foo,
    bar,
    baz,
}
    .some_method();

The indentation of the trailing method call compared to the initializers and the closing brace is surprising. Compare this with what you get with the parenthesized version, even if you force one line per constructor argument:

return MyStruct(  //
           foo,   //
           bar,   //
           baz)
    .some_method();

On that analogy I would expect something more like this:

return MyStruct{
           foo,
           bar,
           baz,
       }
       .some_method();
jacobsa commented 1 month ago

This looks even weirder as an argument to a function call. Here is an example:

  partition->set_field(k3::SomeStruct{
      .foo = bar,
  }
                           .get_blah());