-
-
Notifications
You must be signed in to change notification settings - Fork 262
Description
Hi Andreas,
I am currently learning about coroutines. And even if cppinsights claims to only be an approximation, it is a massive help! Thanks a lot 🎆
While playing around, I came across a minor issue: The promise-constructor-arguments as described by dcl.fct.def.coroutine#5.7 are not supported by cppinsights. To phrase cppreference:
calls the constructor for the promise object. If the promise type has a constructor that takes all coroutine parameters, that constructor is called, with post-copy coroutine arguments. Otherwise the default constructor is called.
I tried to come up with a minimal example, where the promise_type has a constructor of the form promise_type(int& a, char& b, double& c) and the coroutine (coro) has matching function parameters (int a, char b, double c):
#include <coroutine>
#include <utility>
struct my_resumable {
struct promise_type;
using handle_type = std::coroutine_handle<promise_type>;
my_resumable() = default;
my_resumable(handle_type h) : m_handle(h) {}
~my_resumable() { if (m_handle) m_handle.destroy(); }
my_resumable(my_resumable&& other) noexcept : m_handle(std::exchange(other.m_handle, nullptr)) {}
my_resumable& operator=(my_resumable&& other) noexcept {
m_handle = std::exchange(other.m_handle, nullptr);
return *this;
}
handle_type m_handle;
};
struct my_resumable::promise_type {
promise_type() = default;
promise_type(int& a, char& b, double& c) { }
my_resumable get_return_object() {
auto h = my_resumable::handle_type::from_promise(*this);
return my_resumable(h);
}
std::suspend_never initial_suspend() { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
my_resumable coro(int a, char b, double c) {
co_return;
}If you run it through cppinsights, you will see that in line 103/104 the promise object gets constructed like this:
new (&__f->__promise)std::__coroutine_traits_impl<my_resumable>::promise_type{};But instead it should be:
new (&__f->__promise)std::__coroutine_traits_impl<my_resumable>::promise_type{__f->a, __f->b, __f->c};