10-04-2019, 01:51 PM
You are right, your example violates 6-4-5.
When 6-4-3 says jump-statements (which includes goto) "are permitted within the compound statements forming the body of a switch-clause",
it means that you can write code like:
switch(x) {
case 1:
{ goto l1;
// some code
l1:
// more code
break;
}
case 2:
++x;
break;
default:
break;
}
not that you can use goto to leave the switch statement or jump out of the compound statement following the "case" keyword.
When 6-4-3 says jump-statements (which includes goto) "are permitted within the compound statements forming the body of a switch-clause",
it means that you can write code like:
switch(x) {
case 1:
{ goto l1;
// some code
l1:
// more code
break;
}
case 2:
++x;
break;
default:
break;
}
not that you can use goto to leave the switch statement or jump out of the compound statement following the "case" keyword.
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group