Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit move constructor / move assignment for shared_task #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zerodefect
Copy link
Contributor

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
Copy link
Contributor Author

Hi @Amanieu,

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

Thanks.

@Amanieu
Copy link
Owner

Amanieu commented Jun 29, 2022

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

@zerodefect
Copy link
Contributor Author

Thanks for getting back to me.

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

@zerodefect
Copy link
Contributor Author

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.

@Amanieu
Copy link
Owner

Amanieu commented Aug 9, 2022

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
Copy link
Owner

Amanieu commented Aug 10, 2022

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.

@kikaxa
Copy link

kikaxa commented Jun 21, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants