Issue 151521
Summary Clang front-end crash on compiling lambda
Labels clang
Assignees
Reporter olivermadge
    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_bug-86f8f9.sh.log)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to