I have encountered an interesting peculiarity while playing with code. I am using Eclipse CDT 4.5.2 with Cygwin and C++14 turned on (-std=c++14). Variable initialization inside CASE's is normally prohibited, but the following code compiles:
switch( int switchStatement = 11)
{
default:
++j;
break; // break is optional, still compiles even if omitted
case 11:
int caseVariable = 0;
++j;
}
If another CASE is added, then exception "jump to case label" is raised.
switch( int switchStatement = 11)
{
default:
++j;
case 11:
int caseVariable = 0;
++j;
case 12: // exception
++j;
}
Could somebody explain me how it all works?