Skip to content

Key rules that return {} - #561

Open
lucic71 wants to merge 12 commits into
Cpp2Rust:masterfrom
lucic71:12-empty-init-list-rule
Open

lucic71 wants to merge 12 commits into
Cpp2Rust:masterfrom
lucic71:12-empty-init-list-rule

Conversation

@lucic71

@lucic71 lucic71 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

In pre-C++17 we cannot write rules like:

MoveAndCopyCtorsDeleted f1() {
  return MoveAndCopyCtorsDeleted();
}

Because the standard requires that first a temporary is built, then the move or copy ctor is called to return the temporary. The only expression that work is:

MoveAndCopyCtorsDeleted f1() {
  return {};
}

In this format no copy/move ctor is called. The object is returned directly to the caller.

std::atomic is a type with copy deleted and non-existent move.

The translation that I added for atomic is dummy. Just to prove that the rules can be loaded.

@lucic71
lucic71 force-pushed the 12-empty-init-list-rule branch from bcae6f4 to 14d0fc3 Compare October 21, 2026 21:49

This branch has not been deployed

No deployments
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