C++ Logo

std-proposals

Advanced search

Re: [std-proposals] D0000R0: Extensible Scoped Enumerations (draft)

From: Rainer Deyke <rainerd_at_[hidden]>
Date: Sat, 30 May 2026 12:07:26 +0200
On 5/29/26 20:32, Andrey Fokin via Std-Proposals wrote:
> D0000R0: Extensible Scoped Enumerations (draft)
> Author: Andrey Fokin lazzyfox_at_[hidden]
> Date: 2026-04-20
>
> Hello all,
>
> I am submitting a draft proposal for review:
>
> PDF:
> https://github.com/lazzyfox/wg21/blob/main/docs/D0000R0-ExtensibleScopedEnumerations.pdf

Enum inheritance is an obvious extension to C++. The real question is
if it's useful enough to justify adding to the language. The lesser
question is what to do about the edge cases, but most of the edge cases
go away if you just stick to single inheritance.

#define SOME_TEXT_HERE a, b, c
#define SOME_MORE_TEXT_HERE d, e

enum class x { SOME_TEXT_HERE };
enum class y { SOME_TEXT_HERE, SOME_MORE_TEXT_HERE };
enum class z : x { SOME_MORE_TEXT_HERE };
// Enum z is defined as if it were enum y,
// but allow implicit conversion from x to z.

The requirement that enum values not conflict is nonsensical:

// This is legal right now:
enum class binary_digits : std::uint8_t {
   zero = 0,
   nada = 0,
   null = 0,
   one = 1,
   eins = 1,
};

// This would not be, and we don't even have multiple inheritance.
enum class trinary_digits : binary_digits {
   three = 3,
   drei = 3,
};

The real edge case for multiple inheritance is this:

enum class x { a = 10 };
enum class y { b = 12 };
enum class x_plus_c : x { c }; // c has a value of 11
enum class y_plus_c : y { c }; // f has a value of 13
enum class x_plus_y_plus_c : x, y { c }; // What's the value of c now?


-- 
Rainer Deyke - rainerd_at_[hidden]

Received on 2026-05-30 10:07:38