Feature request: enum init shouldn't create a new enumeration

Tommi tommitissari at hotmail.com
Mon Oct 15 01:33:56 PDT 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.


More information about the Digitalmars-d mailing list