-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
coroutine transformation: Support _promise-constructor-arguments_ #536
Comments
Hello @Ukilele,
my pleasure! What you report here is a very interesting case. What I struggle with is this part from your cppreference quote:
my patch would make it look like what you're showing above. However, I wonder whether another interpretation is:
This form would be broken for moved-from objects, so I assume your version is the correct one. Andreas |
Yes, I am pretty sure it is A minor nitpick: According to dcl.fct.def.coroutine#5.7, it should be Thanks, |
Hello @Ukilele,
perfect.
That is an interesting exception. I'm not sure whether C++ Insights currently shows such a case correctly. Do you happen to have an example for this case? Andreas |
Here is a snippet, where we have a class
#include <coroutine>
#include <utility>
struct ClassWithCoro;
struct my_resumable {
struct promise_type {
promise_type(const ClassWithCoro& q1, int& q2) {}
my_resumable get_return_object() {
return my_resumable(my_resumable::handle_type::from_promise(*this));
}
std::suspend_never initial_suspend() { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
using handle_type = std::coroutine_handle<promise_type>;
my_resumable(handle_type h) : m_handle(h) {}
~my_resumable() { if (m_handle) m_handle.destroy(); }
my_resumable(my_resumable&& other) = delete;
handle_type m_handle;
};
struct ClassWithCoro {
my_resumable coro(int x) const {
co_return;
}
}; Like I said earlier, I am still learning about coroutines. But I would say that the transformation looks good to me, except of the issue at hand. I.e. that cppinsights generates new (&__f->__promise)std::__coroutine_traits_impl<my_resumable>::promise_type{}; whereas instead it should generate: new (&__f->__promise)std::__coroutine_traits_impl<my_resumable>::promise_type(*this, __f->x); I hope my example is helpful :) |
Along with the mentioned fix, this patch fixes two other issues: 1) The return statement in the coroutine setup function was missing the `__f`. This error was introduced with the update to Clang 15. 2) The template parameters were missing in the case of a `CXXConversionDecl` where the conversion type was a template.
Along with the mentioned fix, this patch fixes two other issues: 1) The return statement in the coroutine setup function was missing the `__f`. This error was introduced with the update to Clang 15. 2) The template parameters were missing in the case of a `CXXConversionDecl` where the conversion type was a template.
Fixed #536: Call promise constructor if arguments match.
Thank you! 馃殌 馃檪 |
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:
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
):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:
The text was updated successfully, but these errors were encountered: