07-03-2017, 08:53 AM
Rule 6-4-5 requires an unconditional throw or break statement to terminate every non‑empty switch-clause.
But what about a return statement like in the example below.
The return statement for case 0: avoids an unintentional fall-through to next switch-clause.
For that reason an unconditional return at end of a switch-clause should make the switch-clause also compliant to this rule.
Is return as last statement of a switch-clause also compliant to this rule?
But what about a return statement like in the example below.
Code:
switch ( x )
{
case 0:
return; // Compliant or non-compliant?
case 1: // Compliant - empty drop through
case 2: // allows a group
break; // Compliant
case 3:
throw; // Compliant
case 4:
a = b;
// Non-compliant - non empty drop through
default:
; // Non-compliant – default must also have "break"
}
For that reason an unconditional return at end of a switch-clause should make the switch-clause also compliant to this rule.
Is return as last statement of a switch-clause also compliant to this rule?