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

Oleg Smolsky via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 2 08:48:18 PDT 2019


Filed https://bugs.llvm.org/show_bug.cgi?id=41349 so that this does not 
get lost in the mail traffic.

On 2019-03-25 13:49, Oleg Smolsky wrote:
>
> And even further reduced case:
>
> void F() {
>   Call({(Cast)[] { f(); }});
> }
>
> On 2019-03-25 13:46, Oleg Smolsky wrote:
>>
>> 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/20190402/aebe90f3/attachment.html>


More information about the cfe-dev mailing list