Search code examples
c++lambdaclang-format

Leave short lambda used as a middle argument for a function intact using clang-format


I would like to format the code with clang-format and leave lambda used as a middle function argument intact (as is):

void f()
{
    func(0, [] {}, 0);
}

Everything I was trying in clang-format 9.0 (and 11.0.0-2663a25f as well) wraps arguments to the next line, i.e.:

void f()
{
    func(
        0, [] {}, 0); // not-ok
}

If there is no first or/and last argument even built-in -style='WebKit' option gives desired results:

void f()
{
    func([] {}, 0); // ok
    func(0, [] {}); // ok 
    func([] {});    // ok 
}

It seems that something changed (broken) since LLVM 8.0, because 7.1 works as needed. I.e. gives me the same as I had originally:

void f()
{
    func(0, [] {}, 0); // how to achieve this after clang-format?
}

Solution

  • This issue is fixed in LLVM 18. Related closed bug report on GitHub here.