enum MyEnum
{
A,
B,
}
MyEnum Foo(int i)
{
MyEnum mx;
switch(i)
{
case 1:
{
mx = A;
}break;
case 2:
{
mx = B;
}break;
default:
{
throw std::exception("ERROR");
}
}
}
int Main()
{
MyEnum myEnum = Foo(1);
return 0;
}
Without ‘return’ in Foo( ), This code can be compiled and run in VS2010. Is it compiler bug?
VS2010 screenshot to confirm that it can be run
It is not a compiler bug. A missing return doesn’t require a diagnostics from the compiler (but the compiler might emit one), and it leads to undefined behavior – anything can happen.