Skip to content

Handle explicit cast of union member#210

Merged
nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
lucic71:reinterpreted-accessor
Jul 1, 2026
Merged

Handle explicit cast of union member#210
nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
lucic71:reinterpreted-accessor

Conversation

@lucic71

@lucic71 lucic71 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Union members are translated using accessors:

union u { int a; }
*(char *)&u.a = 0xFF;

becomes

struct u { __bytes: Value<Box<[u8]>> }
impl u { pub fn a() -> Ptr<i32> { ... } } // the accessor

u.a().reinterpret_cast<u8>().write(0xFF) // Before this PR it did not compile: (u.a() as Ptr<u8>).write(0xFF)

This PR replaces the wrong (u.a() as Ptr<u8>) pattern with u.a().reinterpret_cast<u8>()

@lucic71

lucic71 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

This has no effect on the existing union tests now, but it's a step forward to unblock them.

@lucic71 lucic71 force-pushed the reinterpreted-accessor branch from 461d4d1 to 117fe7e Compare June 29, 2026 21:40
@nunoplopes nunoplopes merged commit 892566f into Cpp2Rust:master Jul 1, 2026
9 checks passed
@lucic71 lucic71 deleted the reinterpreted-accessor branch July 1, 2026 11:14
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