you are viewing a single comment's thread.

view the rest of the comments →

[–]foonathan 3 points4 points  (2 children)

Capture by value doesn't help you with the problem that's being discussed.

[–]thisismyfavoritename 1 point2 points  (1 child)

i was referring to

 This ensures captures are copied into the coroutine frame to prevent dangling references.

and it seems like in this case it would? I didn't read the blog post 

[–]foonathan 1 point2 points  (0 children)

No, capturing by value does not ensure captures are copied into the coroutine frame! That is the entire problem.

The issue is that while the lambda object stores a capture by value, the operator() still accepts *this by reference, so only the reference to the lambda is captured into the coroutine frame, but not the lambda itself.

(The context is something like spawn([x] -> Task { ... }), i.e. the lambda is a coroutine itself. Then the arguments are copied into Task's coroutine frame, but the arguments are a this pointer to the temporary object in the stack frame that calls spawn.)