[Issue 8157] New: Disallow (dis)equality among two different enums
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 28 13:55:46 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8157
Summary: Disallow (dis)equality among two different enums
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-05-28 13:57:33 PDT ---
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/lyzudurkvguonbmmjqfp@forum.dlang.org
See an answer by Andrei Alexandrescu:
http://forum.dlang.org/thread/lyzudurkvguonbmmjqfp@forum.dlang.org#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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list