Skip to content

Rewrite std::mem::take in rules for records with user-defined move constructor - #365

Closed
lucic71 wants to merge 19 commits into
Cpp2Rust:masterfrom
lucic71:mem-take-rewrite
Closed

lucic71 wants to merge 19 commits into
Cpp2Rust:masterfrom
lucic71:mem-take-rewrite

Conversation

@lucic71

@lucic71 lucic71 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Calling std::mem::take moves the objects and leaves a default constructed value in place. This is wrong for records with user defined move constructors because it drops the side effects inside the user defined move constructor.

This PR rewrites std::mem::take from rules as follows:

  • record has move constructor => rewrite std::mem::take as a call to the move constructor
  • record does not have move constructor and is copyable => convert as rvalue (without clone)
  • record does not have move constructor and is not copyable => convert as fresh rvalue (with clone)
  • record is STL type => use the rule for STL move constructor
  • temporary value => convert as rvalue

@lucic71
lucic71 marked this pull request as draft September 14, 2026 13:16
@lucic71

lucic71 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Depends on #364

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