<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/151521>151521</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang front-end crash on compiling lambda
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          olivermadge
      </td>
    </tr>
</table>

<pre>
    The following code causes clang-19 to crash with the error `clang++-19: error: clang frontend command failed with exit code 139 (use -v to see invocation)`:

```
#include <utility>
#include <cstring>
#include <print>

template <typename TypeTuple>
auto count_types() {
    return []<size_t... Idx>(std::index_sequence<Idx...>) {
        return ([](std::tuple_element_t<Idx, TypeTuple> base) {return base;}(1) + ...);
 }(std::make_index_sequence<std::tuple_size_v<TypeTuple>>{});
}

int main() {
    std::println("{}", count_types<std::tuple<int>>());
 std::println("{}", count_types<std::tuple<int, char>>());
}

```

Interestingly, if I introduce an additional intermediate lambda to extract Idx, it compiles without error:
```
#include <utility>
#include <cstring>
#include <print>

template <typename TypeTuple>
auto count_types() {
    return []<size_t... Idx>(std::index_sequence<Idx...>) {
        return ([]<size_t Index>(std::integral_constant<size_t, Index>) {
            return [](std::tuple_element_t<Index, TypeTuple> base) {return base;}(1);
 }(std::integral_constant<size_t, Idx>()) + ...);
 }(std::make_index_sequence<std::tuple_size_v<TypeTuple>>{});
}

int main() {
    std::println("{}", count_types<std::tuple<int>>());
 std::println("{}", count_types<std::tuple<int, char>>());
}

```

Clang-19 from Arch Linux (version 19.1.7 on x86-64) invoked as `clang++-19 -emit-llvm -Xclang -disable-llvm-passes --std=c++20 clang_bug.cpp -c -o clang`

The same code compiles and runs with the expected result on clang++-20, g++-14 and g++-15

[clang_bug-86f8f9.cpp.log](https://github.com/user-attachments/files/21531707/clang_bug-86f8f9.cpp.log)
[clang_bug-86f8f9.sh.log](https://github.com/user-attachments/files/21531708/clang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