[cfe-dev] clang-format formats initializer_list passed to function oddly

Turing Eret via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 21 09:55:52 PDT 2019


I have the following bit of code (or something very similar):

int main() {
    add_thingie({{Thingie1::ID(), (ThingieHandler)[=](const Object& o) {
do_something1(o); }}, {Thingie2::ID(), (ThingieHandler)[=](const Object& o)
{ do_something2(o); }}});
    return 0;
}

If I run it through clang-format (6.0.0), I get the following output.

C:\clang-format_example>clang-format example_bad.cpp
int main() {
        add_thingie({{Thingie1::ID(), (ThingieHandler)[=](const Object& o)
{ do_something1(o);
}
}
, {
  Thingie2::ID(), (ThingieHandler)[=](const Object &o) { do_something2(o); }
}
});
return 0;
}

Interestingly, if I remove the C-style cast, it produces something sensible.

C:\clang-format_example>clang-format example_good.cpp
int main() {
  add_thingie({{Thingie1::ID(), [=](const Object &o) { do_something1(o); }},
               {Thingie2::ID(), [=](const Object &o) { do_something2(o);
}}});
  return 0;
}

I could not find any set of options that does something remotely sensible
to the original example. Am I missing something?

Turing
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190321/51c19fbb/attachment.html>


More information about the cfe-dev mailing list