Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Support generating scoped enums in C++ #1157

@scaredginger

Description

@scaredginger

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions