Skip to content

Remove remaining places that use Default in the converter - #702

Open
lucic71 wants to merge 14 commits into
Cpp2Rust:masterfrom
lucic71:remove-default
Open

lucic71 wants to merge 14 commits into
Cpp2Rust:masterfrom
lucic71:remove-default

Conversation

@lucic71

@lucic71 lucic71 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Also fixed a bug in ZeroInitialization where data member pointers were initialised to 0 instead of -1.

@nunoplopes

Copy link
Copy Markdown
Contributor

For classes that have a trivial constructor, we can keep Default. That makes the code more idiomatic.

@lucic71

lucic71 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

For classes that have a trivial constructor, we can keep Default. That makes the code more idiomatic.

Done, Default is automatically derived when TriviallyDefaultInitializable is derived and now it's used in the generated code.

@nunoplopes

Copy link
Copy Markdown
Contributor

It's not just about the trivial cases. Any class that has a default constructor that only has trivial fields, even it has non-default initialization can be emitted as a Default impl.

@lucic71

lucic71 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

It's not just about the trivial cases. Any class that has a default constructor that only has trivial fields, even it has non-default initialization can be emitted as a Default impl.

I did that in the last commit:

-    object!(record, Record_19::constructor_1());
-    assert!(({ (*record.borrow()).id } == 100));
+    let mut record: Record_19 = <Record_19>::default();
+    assert!((record.id == 100));

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.

2 participants