AutosarC++17_03-M6.4.4

A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch-statement

Required inputs: IR

Rationale

A switch-label can be placed anywhere within the statements that form the body of a switch statement, potentially leading to unstructured code. To prevent this from happening, the scope of a case-label or default-label shall be the compound statement forming the body of a switch statement. All case-clauses and the default-clause shall be at the same scope.

Example
switch ( x ) 
{
case 1: // Compliant
if ( ... )
{
case 2: // Non-compliant
DoIt ( );
}
break;
default:
break;
}

Note

For legal reasons, this rule’s description is not part of the public documentation.