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

Oleg Smolsky via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 25 13:46:05 PDT 2019


This looks like a bug (or bugs) in LibFormat. Here is one reduced case:

Works:

Call({a, [=]() { something1(o); }, b});

Broken:

namespace ns{
void F() {
   Call({a, (Cast)[=]() { something1(o); }, b});
}
}

The second case counts braces incorrectly.

On 2019-03-21 09:55, Turing Eret via cfe-dev wrote:
> 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
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190325/7f80faa9/attachment.html>


More information about the cfe-dev mailing list