Bug 8157 – Disallow (dis)equality among two different enums
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-28T13:57:00Z
Last change time
2013-01-10T14:59:00Z
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-05-28T13:57:33Z
This enhancement request is related to Issue 3999 but it's not the same problem.
Issue 3999 asks to statically disallow:
enum E1 { A, B }
enum E2 { C, D }
void main() {
E1 a;
assert(a == 0);
}
While this issue asks to statically disallow:
enum E1 { A, B }
enum E2 { C, D }
void main() {
E1 a;
assert(a == E2.C);
assert(a != E2.C);
}
(Well, Issue 3999 asks to disallow both cases, so this issue is a subset of Issue 3999 .)
Discussion:
http://forum.dlang.org/thread/[email protected]
See an answer by Andrei Alexandrescu:
http://forum.dlang.org/thread/[email protected]#post-jpvvm2:242d8l:241:40digitalmars.com
> I do agree that it's wrong to _conflate_ the enumerated value with it
> ordinal, so in this program neither comparison should compile without an
> explicit cast:
>
> enum E1 { A, B }
> enum E2 { C, D }
>
> void main() {
> E1 a;
> assert(a == 0);
> assert(a == E2.C);
> }
>
> The first one is probably difficult to disallow at this time, but the
> second one almost always indicates a bug, confusion, or abuse on the
> user side. We should disallow it.
Comment #1 by andrej.mitrovich — 2013-01-10T14:59:00Z
*** This issue has been marked as a duplicate of issue 6227 ***