www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10965] New: Allow alias initializer as enum member to avoid counter reset

reply d-bugmail puremagic.com writes:
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



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: -------
Sep 04 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10965


Henning Pohl <henning still-hidden.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |henning still-hidden.de



PDT ---
https://github.com/D-Programming-Language/dmd/pull/2529

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 07 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10965


Henning Pohl <henning still-hidden.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 08 2013