| |
 | Posted by Andrej Mitrovic | Permalink Reply |
|
Andrej Mitrovic 
| http://d.puremagic.com/issues/show_bug.cgi?id=10965
Summary: Allow alias initializer as enum member to avoid
counter reset
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody@puremagic.com
ReportedBy: andrej.mitrovich@gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-09-04 17:47:00 PDT ---
I've recently ran into a hard to track bug in my code:
-----
enum MouseAction
{
press,
release,
/** Convenience - equal to $(D press). */
click = press,
double_click, // oops, it's now equal to release!!
}
void main()
{
static assert(MouseAction.release != MouseAction.double_click); // fail
}
-----
Unfortunately the introduction of the convenience member ended up re-setting the enum member init counter, which ended up making "double_click" equal the value of "release".
To avoid such buggy code, but still allow these convenience members, I propose we introduce member aliases as a new feature:
-----
enum MouseAction
{
press,
release,
alias click = press, // same as press, but does not reset the counter!
double_click, // equals release + 1
}
void main()
{
static assert(MouseAction.release != MouseAction.double_click); // ok
}
-----
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
|