[Issue 6226] New: Switch with impossible cases

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 29 17:10:11 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6226

           Summary: Switch with impossible cases
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          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 2011-06-29 17:05:15 PDT ---
In the following code the cases 400 and 200 can't happen, because they are
ouside the values range of char and byte. I suggest to raise a warning in such
cases (this compiles with no errors on DMD 2.053):


void main() {
    char c;
    switch (c) {
        case 'a': break;
        case 400: break;
        default:
    }
    byte x;
    switch (x) {
        case 10: break;
        case 200: break;
        default:
    }
}


See here for real world bug cases:
http://www.viva64.com/en/d/0142/


This too generates no errors, but I think this is less often a bug:

void main() {
    char c;
    if (c == 400) {}
}

-- 
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