[clang] [clang] return type not correctly deduced for discarded lambdas (PR #153921)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 16 13:43:07 PDT 2025


cor3ntin wrote:

> @cor3ntin One thing I'm trying to work out in tests is whether there is any way to get a discarded block that should cause an error in the containing scope but not if it occurred in the lamda instantiation.

There are never any errors ignored in discarded statements. If the `if constexpr` appears in a template its content is not instantiated. But it is always parsed.

If you want to write a tests where the `if constexpr(false)` is in a template, and calls a dependent/generic lambda that can never be instantiated... you can! Maybe something like that:

```cpp
template <typename T>
void f() {
  auto x = []<typename U>(U, U = U::bar) {};
  if constexpr(false) {
        x(T{});
  }
}
int _ = (f<int>(), 0);
```

https://github.com/llvm/llvm-project/pull/153921


More information about the cfe-commits mailing list