[Issue 1560] New: Skip switch warning for complete enum set

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 9 07:36:14 PDT 2007


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

           Summary: Skip switch warning for complete enum set
           Product: D
           Version: 1.021
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: david at acz.org


Consider the following:

void main()
{
    enum T { RED, GREEN, BLUE }
    T t;

    switch (t)
    {
        case T.RED: break;
        case T.GREEN: break;
        case T.BLUE: break;
    }
}

DMD gives two warnings:

warning - foo.d(8): Error: switch statement has no default
warning - foo.d(8): Error: statement is not reachable

A default is not needed as all enum values are handled.  Omitting the default
and warning here gives us the same functionality as g++:

warning: enumeration value `xxx' not handled in switch


-- 



More information about the Digitalmars-d-bugs mailing list