asyncplusplus icon indicating copy to clipboard operation
asyncplusplus copied to clipboard

Add explicit move constructor / move assignment for shared_task

Open zerodefect opened this issue 2 years ago • 7 comments

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)

zerodefect avatar Jun 19 '22 00:06 zerodefect

Hi @Amanieu,

I appreciate you are not working on this project anymore, but is there any possibility of you considering this pull request?

Thanks.

zerodefect avatar Jun 23 '22 15:06 zerodefect

I don't think this has ever worked? IIRC you need to call .share() on a task to turn it into a shared_task.

Amanieu avatar Jun 29 '22 01:06 Amanieu

Thanks for getting back to me.

I'll go away, create an example, and come back to you.

zerodefect avatar Jun 29 '22 09:06 zerodefect

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.

zerodefect avatar Aug 05 '22 11:08 zerodefect

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()};

Amanieu avatar Aug 09 '22 19:08 Amanieu

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.

Amanieu avatar Aug 10 '22 00:08 Amanieu

my guess would be it somehow triggers aggregate initialization instead with slicing task to the basic_task and using that as base. Screenshot 2023-06-21 at 16 45 53

kikaxa avatar Jun 21 '23 14:06 kikaxa