Skip to content

[BUG] Double move when passing by move #413

Open

Description

@JohelEGP

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

Activity

  1. HALL9kv0 commented on May 4, 2023

    @HALL9kv0

    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.

  2. JohelEGP commented on May 4, 2023

    @JohelEGP
    ContributorAuthor

    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.

  3. HALL9kv0 commented on May 4, 2023

    @HALL9kv0

    My apologies, I was referring to the contributors.

  4. JohelEGP commented on May 31, 2023

    @JohelEGP
    ContributorAuthor

    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;
  5. JohelEGP commented on Jul 26, 2023

    @JohelEGP
    ContributorAuthor

    An alternative Expected result
    is a diagnostic saying that x will be moved,
    and thus the explicit move is redundant.

  6. JohelEGP commented on Dec 14, 2023

    @JohelEGP
    ContributorAuthor

    An alternative Expected result
    is a diagnostic saying that x will be moved,
    and thus the explicit move is redundant.

    This isn't true in a generic context.
    So I expect move x to always work in a generic context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions