Skip to content

Translate C++ enums as Rust integers - #325

Merged
nunoplopes merged 4 commits into
Cpp2Rust:masterfrom
lucic71:enums-as-int
Sep 4, 2026
Merged

nunoplopes merged 4 commits into
Cpp2Rust:masterfrom
lucic71:enums-as-int

Conversation

@lucic71

@lucic71 lucic71 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

The previous translation, C++ enums -> Rust enums had two weak points:

  • it did not allow enums that have equal variants, for example enum E { A = 1, B = A }
  • operations on the enum could not be used in const context, for example: int global = E::A != E::B. != for enums is not const so it cannot be used in const expressions like initializing a global variable

The new translation does C++ enums -> Rust integers and the name of the values becomes E_A instead of E::A.

@nunoplopes
nunoplopes merged commit 4b05f90 into Cpp2Rust:master Sep 4, 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