[clang-format] Fix incorrect formatting of lambdas inside brace initialisation
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Mon, 3 Jan 2022 16:32:20 +0000 (17:32 +0100)
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Tue, 4 Jan 2022 07:28:12 +0000 (08:28 +0100)
commite2b6e21f19da6fe0da9349264e43286f0441b4ca
tree3fb8fba169d02bb5c0311df173e42b4093258abf
parent2a0e05100c26473b3ce94507200b55f71a9c9482
[clang-format] Fix incorrect formatting of lambdas inside brace initialisation

Fixes https://github.com/llvm/llvm-project/issues/27146.
Fixes https://github.com/llvm/llvm-project/issues/52943.

Before:

```
namespace ns {

void foo() {
  std::variant<int, double> v;
  std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr; }}, v);
}

} // namespace ns

int break_me() {
  int x = 42;
  return int{[x = x]() {
    return x;
  }()};
}
```

got formatted as:
```
namespace ns {

void foo() {
  std::variant<int, double> v;
  std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr;
}
} // namespace ns
, v);
}

} // namespace ns

int break_me() {
  int x = 42;
  return int{[x = x](){return x;
}
()
}
;
}
```

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D116553
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp