Issue 179549
Summary Bad formatting of lambda _expression_ with trailing return type
Labels new issue
Assignees
Reporter inicula
    This:

```cpp
#include <optional>

using T = std::optional<int>;

int main() {
  auto foo = []() -> T {
    return T{1};
  }().value();
}
```

gets formatted to:

```cpp
#include <optional>

using T = std::optional<int>;

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 <optional>

using T = std::optional<int>;

int main() {
  auto foo = []() {
    return T{1};
 }().value();
}
```

gets formatted to:

```cpp
#include <optional>

using T = std::optional<int>;

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
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to