Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10080 closed Feature Requests (invalid)

Make optional copy-ctor

Reported by: voivoid@… Owned by: olli
Milestone: To Be Determined Component: coroutine
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:


I know that coroutines are made movable only to prevent UB during a stack unwinding of RAII objects. But there could be only POD objects and copy-ctor should work perfectly fine ( my scenario is a binary tree iterator that has a coroutine ).

So I suggest to make an optional ( via template parameter? ) copy constructor.

Change History (2)

comment:1 Changed 5 years ago by olli

Resolution: invalid
Status: newclosed

making coroutine copy-able would require to copy the stack. this is dangerous even with POD. you get unexpected behaviour if you copy a stack which has references/pointers to objects on the stack.

int i = 0;
int * j = & i;

If you copy the stack above, j of the new (copied-to) stack would contain the address of i of the original (copied-from) stack.

comment:2 Changed 5 years ago by anonymous

I agree that API should encourage a right use and discourage a wrong one. But I believe most of boost::coroutine users understand it's basic principles and a potential problem that could arise if the optional copy-ctor is being used. So I suggest a little on-my-own-risk freedom.

Note: See TracTickets for help on using tickets.