[Bug c++/124729] New: [coroutines] await-expressions are split in a brace-init-list
ddvamp007 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Mar 31 12:06:15 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124729
Bug ID: 124729
Summary: [coroutines] await-expressions are split in a
brace-init-list
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ddvamp007 at gmail dot com
Target Milestone: ---
https://godbolt.org/z/465n8bx93
When a brace-init-list for array initialization contains await-expressions, its
evaluation is effectively split into two phases: the await-ready and
await-suspend parts of all await-expressions are evaluated first, followed by
the evaluation of the initializers.
#include <coroutine>
#include <iostream>
struct Tag {
struct promise_type {
Tag get_return_object() { return {}; }
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
};
struct S {
S() { std::cout << " S" << std::endl; }
~S() { std::cout << "~S" << std::endl; }
};
struct Awaiter {
auto await_ready() {
std::cout << "ready" << std::endl;
return false;
}
auto await_suspend(auto) {
std::cout << "suspend" << std::endl;
return false;
}
auto await_resume() {
std::cout << "resume" << std::endl;
return S{};
}
};
auto make() {
std::cout << "make" << std::endl;
return S{};
}
Tag Coroutine() {
S arr[] = {co_await Awaiter{},
make(),
co_await Awaiter{}};
}
int main() {
Coroutine();
}
--std=c++2c -O0 -pedantic -Wall -Wextra
Output:
ready
suspend
ready
suspend
resume
S
make
S
resume
S
~S
~S
~S
More information about the Gcc-bugs
mailing list