https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124730
Bug ID: 124730
Summary: [coroutines] Missing destructor call when a coroutine
is destroyed during aggregate initialization
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/ajqxYqoef
If a coroutine is suspended and then destroyed during aggregate initialization,
the members that have already been initialized are not destroyed.
#include <coroutine>
#include <iostream>
struct S {
S() { std::cout << " S" << std::endl; }
~S() { std::cout << "~S" << std::endl; }
};
struct Tag : std::coroutine_handle<> {
struct promise_type {
Tag get_return_object() {
return {std::coroutine_handle<promise_type>::from_promise(*this)};
}
std::suspend_never initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
};
struct Awaiter {
bool suspend;
auto await_ready() {
std::cout << "ready" << std::endl;
return false;
}
auto await_suspend(auto) {
std::cout << "suspend" << std::endl;
return suspend;
}
auto await_resume() {
std::cout << "resume" << std::endl;
return S{};
}
};
struct A {
S s1;
S s2;
};
Tag Coroutine() {
A s = {.s1 = co_await Awaiter{false},
.s2 = co_await Awaiter{true}};
}
int main() {
Coroutine().destroy();
}
--std=c++2c -O0 -pedantic -Wall -Wextra
Output:
ready
suspend
resume
S
ready
suspend