http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57170



             Bug #: 57170

           Summary: No diagnostic for a negative case when switching over

                    unsigned

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: vvnic.ho...@gmail.com





A signed->unsigned conversion is narrowing, so -1 is not a converted constant

expression. However, the following emits no warning with -Wall, with or without

-std=c++11:



int main() {

    unsigned a = 10;

    switch (a) {

        case -1:

            break;

    }

    return 0;

}



But replacing "unsigned" with any smaller unsigned type (unsigned char or

unsigned short) yields the following warning:



test.cpp:4:9: warning: case label value is less than minimum value for type

[enabled by default]

   case -1:

Reply via email to