https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98976
Bug ID: 98976
Summary: [coroutines] co_return in a switch statement doesn't
make a generic lambda non-constexpr
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mail+gnu at tzik dot jp
Target Milestone: ---
In a repro case below, the lambda is wrongly handled as a constexpr and its
co_return causes a compile error, as a coroutine can not be constexpr.
https://wandbox.org/permlink/y4pEMCNki1ndzJYI
The gcc here is the trunk version as of today, and the command was:
$ g++ -c -std=c++20 failcase.cc
--- failcase.cc
#include <coroutine>
struct future {
struct promise_type {
std::suspend_always initial_suspend() noexcept { return {};}
std::suspend_always final_suspend() noexcept { return {}; }
void unhandled_exception() {}
future get_return_object() { return {}; }
void return_void() {}
};
};
void failcase() {
auto foo = [](auto&&) -> future {
switch (42) {
case 42:
co_return;
}
};
foo(1);
}
----
The error message was:
----
prog.cc: In instantiation of 'failcase()::<lambda(auto:1&&)> [with auto:1 =
int]':
prog.cc:20:9: required from here
prog.cc:17:9: error: 'co_return' cannot be used in a 'constexpr' function
17 | co_return;
| ^~~~~~~~~