Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating scoped enums in C++ #1157

Open
scaredginger opened this issue Jul 12, 2022 · 2 comments
Open

Support generating scoped enums in C++ #1157

scaredginger opened this issue Jul 12, 2022 · 2 comments

Comments

@scaredginger
Copy link

https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations

Scoped enums (enum class) fix several problems with traditional, unscoped enums. Most notably

  1. They do not implicitly convert to or from integer types
  2. They do not pollute the parent namespace with their constants by default

I notice the compiler currently hacks around the second issue with unscoped enums by defining a namespace for the enum. However, in my opinion, (1) is still worth addressing and it would be nice to have slightly cleaner generated headers.

Given that changing all enums to scoped enums would break existing code, I would suggest adding a flag for this behaviour when compiling C++, such as --scoped-enum.

@chwarr
Copy link
Member

chwarr commented Jul 12, 2022

Agreed that changing all enums would be a breaking change. A --scoped-enum flag makes sense.

Is this something you'd be able to contribute?

@scaredginger
Copy link
Author

Awesome, thanks. It's been a while since I've done any Haskell, but I should be able to figure it out. I'll give it a shot in any case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants