C++ Logo

std-proposals

Advanced search

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

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Fri, 24 Mar 2023 18:54:35 +0300
On 3/24/23 18:33, Arthur O'Dwyer via Std-Proposals wrote:
> On Fri, Mar 24, 2023 at 11:17 AM Andrey Semashev via Std-Proposals
> <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>>
> wrote:
>
> On 3/24/23 18:05, Oleksandr Koval via Std-Proposals wrote:
> > Actually, allowing default values can break
> > existing code because right now `Enum e{};` always means e = 0, after
> > your change the value will be different.
>
> No existing code uses "default:" for marking the default enum value
> because currently this syntax is invalid. So this is not a breaking
> change.
>
>
> It's a breaking change to the programmer's intuition, though, if they're
> used to `T t = T();` meaning "zero-initialization" for scalar types.

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.

Received on 2023-03-24 15:54:48