Skip to content

[BUG] Cannot call the std::move algorithm #1167

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

Closed
bluetarpmedia opened this issue Jul 17, 2024 · 2 comments
Closed

[BUG] Cannot call the std::move algorithm #1167

bluetarpmedia opened this issue Jul 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@bluetarpmedia
Copy link
Contributor

Describe the bug
Cppfront prevents the use of the utility rvalue cast function std::move since Cpp2 has the move keyword for params & args, but this means Cpp2 cannot call the overloaded std::move algorithm.

To Reproduce
Run cppfront on this code (translated from the cppreference example):

f: (n: int) = {
    std::this_thread::sleep_for(std::chrono::seconds(n));
    std::cout << "thread (n)$ ended" << std::endl;
}

main: () = {
    v: std::vector<std::jthread> = ();
    v.emplace_back(f, 1);
    v.emplace_back(f, 2);
    v.emplace_back(f, 3);
    l: std::list<std::jthread> = ();

    // std::copy() would not compile, because std::jthread is noncopyable
    std::move(v.begin(), v.end(), std::back_inserter(l));
}

Repro on Godbolt

The error is:

error: std::move is not needed in Cpp2 - use 'move' parameters/arguments instead
@bluetarpmedia bluetarpmedia added the bug Something isn't working label Jul 17, 2024
@DyXel
Copy link
Contributor

DyXel commented Jul 17, 2024

TIL there's a std::move that is not the usual one to obtain a rvalue-ref. I guess the fix would be to check if the function is being called with just 1 argument?

@hsutter
Copy link
Owner

hsutter commented Jul 17, 2024

Thanks, good catch! I didn't know about that algorithm either. I see there isn't a similar forward algorithm so I just need to adjust this for move...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants