Translate user defined moves - #369
Merged
nunoplopes merged 18 commits intoSep 17, 2026
Merged
Conversation
When the move constructor is user written (1) or the move constructor is defaulted/implicit and copy constructor is user written (2). The rationale for 2 is: if user-written move constructor is defaulted then the first choice is to call .clone(). But if the copy constructor is user written, then that's wrong. So force the synthetization of the move constructor in that case.
Related to Cpp2Rust#363
lucic71
marked this pull request as draft
September 14, 2026 20:16
lucic71
marked this pull request as ready for review
September 15, 2026 08:22
nunoplopes
reviewed
Sep 15, 2026
|
|
||
| Holder h1(4); | ||
| h1.p.reset(new int(9)); | ||
| Holder h2 = std::move(h1); |
Contributor
There was a problem hiding this comment.
the translation of this is calling the copy constructor rather than move, I think.
Contributor
Author
There was a problem hiding this comment.
It's the move constructor. Copy constructor is deleted because Holder contains unique_ptr which is not copy
Contributor
|
This strategy works while fields are boxed in Values, but otherwise we need move constructors to call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR translates move constructors as ordinary constructors:
fn S_pmutS(_a0: *mut S) -> Self.The rules for translating and using the move constructors are:
.clone()on moveFor 1 and 2, we always use the translated move constructor because it might contain custom logic that needs to run on every move. For 3 we use
.clone()because it has the same effect as a move would have. For 4.clone()is not available (deleted) or might contain custom logic (user-written) so we synthesize an implicit/defaulted move constructor and use it.std::movebecomes a transparent construct, i.e. no move decision is taken at the time of the cast. It's only used by clang to choose the right constructor. Moves happen on CXXConstructExpr.Each STL type has move construction rules. Rules that move using
std::mem::takehave their bodies rewritten as follows:std::mem::takeas a call to the move constructor