MISRA Discussion Forums

Full Version: Rule 15.3, switch's, and "fallthru"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Rule 15.3 states, "For the purposes of this rule, a switch-clause that does not consist of a compound statement is treated as if it were a block." What if the switch-clause did not end in an unconditional "break;"? While I understand such code would violate other rule(s), the point raised remains: would the following code violate this rule?
Code:
...
switch( a )
{
case 1:
    if( f(a) > 8 )
        goto b;
    doingSomething();
case 2:
    doingSomeOtherThing();
b:
    tada( a );
    break;
default:
    break;
}
...
Rule 15.3 is described in terms of switch-clause, which is defined in the amplification of rule 16.1.
As the questioner stated, the above example breaks several rules (e.g. 16.1, 16.3 and 15.6).

The Working group feels that in this example the code between "case 2 and break" should be considered as a switch-clause, but not the code between "case 1 and break". Therefore according to the amplification the code between "case 2 and break" should be treated as if it were a block. The goto would therefore be a jump into a block, which would violate rule 15.3.