cppfront
cppfront copied to clipboard
[BUG] Double move when passing by move
Title: Double move when passing by move.
Minimal reproducer (https://cpp2.godbolt.org/z/31sPe9xMj):
main: () = {
x := 0;
:(y) = 0;
(move x);
}
Commands:
cppfront -clean-cpp1 main.cpp2
Expected result:
[](auto const& y) -> void { 0; }
(std::move(x));
Actual result and error:
[](auto const& y) -> void { 0; }
(std::move(std::move(x)));
I fixed it locally, I don't know if it breaks something else in the process. In cppfront.h, line under 1628:
line 1624 // For an explicit 'forward' apply forwarding to correct identifier
assert (!current_args.empty());
if (current_args.back().pass == passing_style::forward) {
add_forward = current_args.back().ptoken == n.identifier;
line 1628 }
I have added :
// If explicit 'move' is used then don't add move
if (current_args.back().pass == passing_style::move) {
add_move = false;
}
Let me know if this works or not, I look forward to contributing more actively, but for the time being I'm familiarizing my self with the compiler code.
Let me know if this works or not, I look forward to contributing more actively, but for the time being I'm familiarizing my self with the compiler code.
I can't know, as I don't have working code. Just lots of snippets compliant to the grammar.
My apologies, I was referring to the contributors.
Now I can confirm that it works, and there's just one change to existing tests:
- v = X<19>(); std::cout << "move(v) as X<19> = " + cpp2::to_string(int(cpp2::as_<X<19>>((std::move(std::move(v)))))) << std::endl;
+ v = X<19>(); std::cout << "move(v) as X<19> = " + cpp2::to_string(int(cpp2::as_<X<19>>((std::move(v))))) << std::endl;
An alternative Expected result
is a diagnostic saying that x will be moved,
and thus the explicit move is redundant.
An alternative Expected result is a diagnostic saying that
xwill be moved, and thus the explicitmoveis redundant.
This isn't true in a generic context.
So I expect move x to always work in a generic context.