Skip to content

Translate user defined moves - #364

Closed
lucic71 wants to merge 16 commits into
Cpp2Rust:masterfrom
lucic71:user-defiend-move
Closed

lucic71 wants to merge 16 commits into
Cpp2Rust:masterfrom
lucic71:user-defiend-move

Conversation

@lucic71

@lucic71 lucic71 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

This PR translates move constructors (defaulted or implicit or user written) as ordinary constructors: fn S_pmutS(_a0: *mut S) -> Self. Defaulted and implicit ones are first synthesized by Sema.

Some notes about the implementation:

  1. This below check is related to Freshness is not tracked correctly #363. It will disappear after the issue is solved.
  // TODO: set freshness correctly to avoid stale computed_expr_type_
  if (expr->isGLValue()) {
    SetValueFreshness(expr->getType());
  }
  1. Rules that move always translate to std::mem::take which is wrong if the argument of the rule has a user defined move constructor. I will solve this in a future PR (Rewrite std::mem::take in rules for records with user-defined move constructor #365) where I will rewrite std::mem::take to use the move constructor if the argument has one.

@lucic71

lucic71 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Depends on #362

@lucic71

lucic71 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

I will close this and split this PR into multiple ones. The converter is fine, but the tests fail because of library differences.

The STL between my local machine and ubuntu/macos is different. The STL in the runners forces the instantiation of move constructors that my local library does not force. Because of this, in the runners there are extra move constructors that are not present in the generated code on my machine.

For example:

struct S { int a; }

std::vector<S> v;
// in the runner's library, this forces a move constructor on S that my library does not have
v.erase(...);

Even if I update my library to be on par with ubuntu, the macos will still fail.

So I will translate all move constructors from all user defined structs, even if they are not used in the code.

@lucic71 lucic71 closed this Sep 14, 2026
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.

1 participant