https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96784
Bug ID: 96784 Summary: Templated lambda body remains constexpr despite having co_await in body Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kacper.slominski72 at gmail dot com Target Milestone: --- When a templated lambda has a fold expression with co_await inside of it in it's body, it remains constexpr which causes a compile error. When compiling the following code (with "-std=c++20 -fcoroutines -Wall -Wextra -c"): #include <coroutine> #include <utility> #include <cstddef> struct dummy_coro { using promise_type = dummy_coro; bool await_ready() { return false; } void await_suspend(std::coroutine_handle<>) { } void await_resume() { } dummy_coro get_return_object() { return {}; } dummy_coro initial_suspend() { return {}; } dummy_coro final_suspend() { return {}; } void return_void() { } void unhandled_exception() { } }; dummy_coro foo() { co_await []<size_t ...I>(std::index_sequence<I...>) -> dummy_coro { ((co_await [](int){ return std::suspend_never{}; }(I)), ...); }(std::make_index_sequence<1>{}); } The following error is produced: test.cpp: In instantiation of ‘_Z3foov.actor(foo()::_Z3foov.frame*)::<lambda(std::index_sequence<I ...>)> [with long unsigned int ...I = {0}; std::index_sequence<I ...> = std::integer_sequence<long unsigned int, 0>]’: test.cpp:20:33: required from here test.cpp:19:5: error: ‘co_await’ cannot be used in a ‘constexpr’ function 19 | ((co_await [](int){ return std::suspend_never{}; }(I)), ...); | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The error goes away when the body also contains a co_return/co_await/co_yield that is not in a fold expression.