Bug 8816 – It should be illegal for enums to declare members named init, max, or min
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-13T23:57:00Z
Last change time
2017-02-07T09:09:13Z
Keywords
bootcamp
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2012-10-13T23:57:05Z
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.
Comment #1 by issues.dlang — 2012-10-14T00:05:18Z
See also issue# 8817.
Comment #2 by alex — 2012-10-14T00:36:24Z
For what it's worth, I agree that it's nonsensical to even allow this. It's just inviting catastrophe.
Comment #3 by andrei — 2016-10-15T17:26:00Z
Should be a nice thing for a bootcamper to work on.
Comment #4 by razvan.nitu1305 — 2017-02-07T09:08:14Z
Cannot reproduce on DMD64 D Compiler v2.074.0-devel-4ee9f51 Ubuntu 16.04 64-bit.
For all test cases (min/max/init) the compiler outputs "Cannot modify manifest constant $constants".