www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8816] New: It should be illegal for enums to declare members named init, max, or min

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8816

           Summary: It should be illegal for enums to declare members
                    named init, max, or min
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PDT ---
TDPL (p.275) specifically allows for enums to declare members named min, max,
and init and then immediately tells you that it's a dumb idea to do so.
Allowing it is bound to break generic code, since it allows you to do nonsense
like

enum MyEnum : int {max, min, init}

completely breaking any guarantees about what the mean. And note this fun
situation:

enum MyEnum : int { a, b, c, init }

void main()
{
    MyEnum e;
    assert(e == MyEnum.a);
    assert(MyEnum.init == MyEnum.a);
}

The first assertion passes and the second fails, meaning that the declartion of
init has effectively hidden the real init. I'd strongly argue that allowing the
overloading init, min, and max should be disallowed. Allowing it gains us
nothing and just causes bugs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 13 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8816




PDT ---


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8816


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alex lycus.org



CEST ---
For what it's worth, I agree that it's nonsensical to even allow this. It's
just inviting catastrophe.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 14 2012