Skip to content

Allow initialization of enums in global context#64

Merged
nunoplopes merged 3 commits into
Cpp2Rust:masterfrom
lucic71:enum-cast
May 10, 2026
Merged

Allow initialization of enums in global context#64
nunoplopes merged 3 commits into
Cpp2Rust:masterfrom
lucic71:enum-cast

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 9, 2026

Previously, in C, enums were initialized with the Enum::from(X as i32) pattern because enum variants are represented as int and the type of variable is represented as enum.

The From trait is not allowed in global context because it's non-const. This PR fixes this by short-circuiting ConvertIntegerToEnumeralCast to emit X instead of Enum::from(X as i32)

@nunoplopes nunoplopes merged commit 157f292 into Cpp2Rust:master May 10, 2026
9 checks passed
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