www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8157] New: Disallow (dis)equality among two different enums

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



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: -------
May 28 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8157


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |DUPLICATE



14:59:00 PST ---
*** This issue has been marked as a duplicate of issue 6227 ***

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