Feature request: enum init shouldn't create a new enumeration
Daniel Murphy
yebblies at nospamgmail.com
Wed Oct 17 07:00:41 PDT 2012
https://github.com/D-Programming-Language/dmd/pull/673
"Tommi" <tommitissari at hotmail.com> wrote in message
news:ozvdphftlwxkeumrnvoq at forum.dlang.org...
> On Monday, 15 October 2012 at 08:25:18 UTC, Tommi wrote:
>> in reality, it's very easy to write a bug that makes an enum variable
>> have an invalid value. E.g:
>
> Writing that bug wasn't as easy as I thought though. Here's the code with
> a bug:
>
> enum MyEnum { first, second, third }
>
> auto me = MyEnum.min;
>
> while (me <= MyEnum.max)
> {
> // do something
> ++me;
> }
>
> final switch (me) // this should throw
> {
> case MyEnum.first: break;
> case MyEnum.second: break;
> case MyEnum.third: break;
> }
>
> Instead, currently this code runs just fine, none of the switch cases are
> taken. So, this bug might manifest itself very far from where it actually
> should have been throwing: on that final switch expression. Thus hunting
> this bug down could be tedious.
More information about the Digitalmars-d
mailing list