I’m a big fan of skipping the “default:” label in a enum-switch-case. So I get compiler warnings, when the enum has a new value which is not handled by the switch-case.
Now a colleague stated, that when passing an integer to this switch-case which is not covered by the enumeration I will get a segmentation fault.
At least the gcc we re using handles it correctly. Also the Visual Studio documentation says: If “none of the constants match the constants in the case labels and default label is not present >>> Control is transferred to the statement after the switch statement.”
Is this the standard and thus the behaviour of all (or at least the most) compilers?
The MS compiler seems to do it right. Here’s what the standard says (6.4.2/5):