https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128084
Bug ID: 128084
Summary: internal compiler error with template lambda and
coroutine
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Patrick.Nicolas at arteris dot com
Target Milestone: ---
When building the following code (g++ -std=c++23):
#include <iostream>
#include <generator>
template <typename T>
auto generate() {
return []() -> std::generator<int> {
co_yield 0;
};
}
template <typename Inner>
auto wrap(Inner inner) -> std::generator<int>
{
for (auto const& x: inner())
co_yield x;
}
auto foo() {
return [](auto const&) {
return wrap(generate<int>());
};
}
int main() {
for (int x: foo()(0))
std::cout << x << std::endl;
}
GCC highlights the lambda in the generate function and fails with a
segmentation fault.
The issue first happens on version 15 (15.1 on compiler explorer) and is still
present in version 16.2.1.