October 15, 2012
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.
October 17, 2012
https://github.com/D-Programming-Language/dmd/pull/673

"Tommi" <tommitissari@hotmail.com> wrote in message news:ozvdphftlwxkeumrnvoq@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.


1 2
Next ›   Last »