C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A proposal on default enum initialization

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Fri, 24 Mar 2023 17:29:29 +0100
On 24/03/2023 16:54, Andrey Semashev via Std-Proposals wrote:
> Every change is breaking someone's intuition. Intuition is not factual,
> it's personal. For example, when I see `T()` I do not assume zero
> initialization at all, my first thought would be "it invokes the default
> constructor of T", which may or may not produce something that is zero
> initialized. If you want zero then you should spell zero.
>
> Anyway, I was stating that the change would not break existing code, and
> I maintain this. Therefore it is not a breaking change, factually.

The breaking bit is that, right now, for a type T, is_enum_v<T> == true
always implies is_trivially_default_constructible<T> == true (and
is_trivial_v<T> == true, etc.), as well as "value initializable by
0-filling". I wouldn't be surprised at all if there is code relying on
this; adding user-defined constructors / defaults / ... to enumerations
would break such code.

Personally I think that the perfect time to improve on enumerations
(e.g. give them the possibility of having constructors / member
functions; making it illegal to convert from an integral not matching
any enumerator; etc.) was when `enum class` was added, but alas that
didn't happen.


My 2 c,
-- 
Giuseppe D'Angelo

Received on 2023-03-24 16:29:33