Comments (5)
Hello @Ukilele,
I am currently learning about coroutines. And even if cppinsights claims to only be an approximation, it is a massive help! Thanks a lot 🎆
my pleasure!
What you report here is a very interesting case. What I struggle with is this part from your cppreference quote:
with post-copy coroutine arguments
my patch would make it look like what you're showing above. However, I wonder whether another interpretation is:
new (&__f->__promise)std::__coroutine_traits_sfinae<my_resumable>::promise_type{a, b, c};
This form would be broken for moved-from objects, so I assume your version is the correct one.
Andreas
from cppinsights.
Yes, I am pretty sure it is __f->a
and not a
. This gets also confirmed by https://lewissbaker.github.io/2022/08/27/understanding-the-compiler-transform. The exception to that rule is the *this
object in the case that the coroutine is a non-static member function. See: dcl.fct.def.coroutine#4: If the coroutine is a non-static member function, then "q1 is an lvalue that denotes *this".
A minor nitpick: According to dcl.fct.def.coroutine#5.7, it should be (__f->a, __f->b, __f->c)
, so using parentheses instead of braces. But I don't know if there can be any observable difference between these two.
Thanks,
Kilian
from cppinsights.
Hello @Ukilele,
Yes, I am pretty sure it is __f->a and not a.
perfect.
The exception to that rule is the *this object in the case that the coroutine is a non-static member function. See: dcl.fct.def.coroutine#4: If the coroutine is a non-static member function, then "q1 is an lvalue that denotes *this".
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
from cppinsights.
Here is a snippet, where we have a class ClassWithCoro
and
- The class
ClassWithCoro
has a member functioncoro
which is a coroutine (line 26) and - The
promise_type
has a constructor (line 8) which takes aconst ClassWithCoro& q1
(the lvalue that denotes*this
) and aint& q2
(the remaining post-copy coroutine arguments).
#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 :)
from cppinsights.
Thank you! 🚀 🙂
from cppinsights.
Related Issues (20)
- crash when parse cpp file HOT 1
- different result from godbolt HOT 1
- Incorrect move-only lambda code generation HOT 1
- Superfluous parentheses in declarations are handled incorrectly HOT 4
- Show initialization of non-local variables
- explicit casting for const HOT 2
- NRVO translation is not NRVO eligible HOT 2
- Segmentation Fault: Stack dump without symbol names HOT 1
- structured binding with lambda reports 'Segmentation fault' HOT 1
- Structure binding variables is rvalue reference? HOT 2
- How do I use it with cmake project HOT 2
- can not open "libxml2s.lib" ??? what is "libxml2s.lib" ? from where? HOT 4
- Static casts missing with inherited classes
- Lambda Capture Variable Not Used in Generated Code HOT 2
- build failed on ubuntu HOT 2
- HelloGitHub Badge
- [[likely]] and [[unlikely]] delete condition bodies HOT 1
- std::initializer_list transformation produces invalid code HOT 1
- Segmentation fault with `noexcept( condition )` HOT 2
- Master card HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppinsights.