asyncplusplus
asyncplusplus copied to clipboard
Add explicit move constructor / move assignment for shared_task
When upgrading to using gcc-11 with C++ 20, it is no longer possible to assign a task to a shared_task as in:
async::shared_task<cb_result> task{async::make_task(cb_result::CB_S_OK)};
Therefore an explicit move-constructor and move-assignment operator have been added to shared_task:
shared_task(task<Result>&& other)
shared_task& operator=(task<Result>&& other)
Hi @Amanieu,
I appreciate you are not working on this project anymore, but is there any possibility of you considering this pull request?
Thanks.
I don't think this has ever worked? IIRC you need to call .share()
on a task
to turn it into a shared_task
.
Thanks for getting back to me.
I'll go away, create an example, and come back to you.
This took me longer to get around to than I had hoped. I've had some time to go create a demo project in a public repo that hopefully demonstrates the issue at hand:
https://github.com/zerodefect/asyncpp_assignment_example
In the CMakeLists.txt, if you flip:
set(CMAKE_CXX_STANDARD 17)
between existing value and set(CMAKE_CXX_STANDARD 20)
, you should hopefully get different compilation results.
For the record, I'm building with gcc v11.2 on Ubuntu v22.04 LTS.
This code should never have worked in the first place and I don't understand why it worked in C++17. The proper way to convert a task
to a shared_task
is to use the .share()
function.
async::shared_task<cb_result> task{async::make_task(cb_result::CB_S_OK).share()};
If you can find out why it was working on C++17, I'd be happy to accept a patch that removes the implicit conversion.
my guess would be it somehow triggers aggregate initialization instead with slicing task to the basic_task and using that as base.