Bad formatting of lambda expression with trailing return type
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This:
```cpp
#include
using T = std::optional;
int main() {
auto foo = []() -> T {
return T{1};
}().value();
}
```
gets formatted to:
```cpp
#include
using T = std::optional;
int main() {
auto foo = []() -> T {
return T{1};
}()
.value();
}
```
Which seems like a bug (why is the `.value()` part there?).
On the other hand this (note: trailing return type omitted):
```cpp
#include
using T = std::optional;
int main() {
auto foo = []() {
return T{1};
}().value();
}
```
gets formatted to:
```cpp
#include
using T = std::optional;
int main() {
auto foo =
[]() {
return T{1};
}()
.value();
}
```
which is much more reasonable.
Config file:
```
---
Language: Cpp
Standard: Auto
AllowShortLambdasOnASingleLine: None
```
`clang-format` version: 21.1.7
Contributor guide
Assessment
This issue has not been assessed yet.