Guard code after switch on enum is never reached
<p>I have just hit a confusing problem when trying to compile some code using g++ 4.4.3.</p>

<p>The code below compiles fine, but instead of hitting the expected assert when I pass an 'invalid' enum value, the function just returns 1. What I find even stranger is that when I uncomment the lines pertaining to the E3 enum value, things start working as expected.</p>

<p>The fact that there is no default entry in the switch block is by design. We compile with the -Wall option to get warnings of unhandled enum values.</p>

<pre><code>enum MyEnum
{
    E1,
    E2, 
    //E3
};

int doSomethingWithEnum(MyEnum myEnum)
{
    switch (myEnum)
    {
        case E1: return 1;
        case E2: return 2;
        //case E3: return 3;
    }

    assert(!"Should never get here");
    return -1;
}

int main(int argc, char **argv)
{
    // Should trigger assert, but actually returns 1
    int retVal =  doSomethingWithEnum(static_cast&lt;MyEnum&gt;(4));
    std::cout &lt;&lt; "RetVal=" &lt;&lt; retVal &lt;&lt; std::endl;

    return 0;
}
</code></pre>
