Skip to content

Translate in-class initializers in Default trait - #332

Open
lucic71 wants to merge 7 commits into
Cpp2Rust:masterfrom
lucic71:in-class-initializer
Open

Translate in-class initializers in Default trait#332
lucic71 wants to merge 7 commits into
Cpp2Rust:masterfrom
lucic71:in-class-initializer

Conversation

@lucic71

@lucic71 lucic71 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

No description provided.

struct S {
int a = 1;
char b = 2;
Inner c = {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add another test:

Inner d;

should be initialized like c

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

S {
a: 1,
b: (2 as libc::c_char),
c: Inner { x: 3, y: 4 },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c should be initialized like d

@lucic71 lucic71 Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if Inner is defined as:

struct Inner {
  int x; // was int x = 3;
  int y = 4;
}

?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inner x{} would initialize 'x' to zero, While 'Inner x' doesn't. But we probably need to default initialize everything anyway.

@nunoplopes nunoplopes changed the title Translate in-class initialziers in Default trait Translate in-class initializers in Default trait Sep 12, 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.

2 participants