This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [c++] switch ( enum ) vs. default statment.


On 1/23/07, Paweł Sikora <pluto@agmk.net> wrote:
typedef enum { X, Y } E;
int f( E e )
{
        switch ( e )
        {
                case X: return -1;
                case Y: return +1;
        }

+ throw runtime_error("invalid value got shoehorned into E enum")


}

In this example g++ produces a warning:

e.cpp: In function 'int f(E)':
e.cpp:9: warning: control reaches end of non-void function

Adding `default' statemnet to `switch' removes the warning but
in C++ out-of-range values in enums are undefined.

nevertheless, that integer type might get its bits twiddled somehow.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]