06-07-2024, 02:20 AM
Hello,
My question is about the third example for MISRA C++ 2023 Rule 9.6.2: "A goto statement shall reference a label in a surrounding block".
void f3(int32_t i, int32_t x, int32_t y)
{
switch( i )
{ // statement A
case 0:
if ( x < y )
goto L3; // Non-compliant
break;
case 1:
L3:
break;
}
}
I am not sure why this is non-compliant. In terms of the amplification of the rule, "A goto statement shall be enclosed in a statement that directly encloses its reference label", statement A is the compound statement as shown above. I believe the goto statement is enclosed within statement A, and statement A directly-encloses the reference label (L3).
The MISRA C 2012 and MISRA C 2023 versions of the equivalent rule 15.3 provide a different amplification that directly addresses this: "A switch-clause that does not consist of a compound statement is treated as if it were a block"
Please let me know what you think. Thank you.
My question is about the third example for MISRA C++ 2023 Rule 9.6.2: "A goto statement shall reference a label in a surrounding block".
void f3(int32_t i, int32_t x, int32_t y)
{
switch( i )
{ // statement A
case 0:
if ( x < y )
goto L3; // Non-compliant
break;
case 1:
L3:
break;
}
}
I am not sure why this is non-compliant. In terms of the amplification of the rule, "A goto statement shall be enclosed in a statement that directly encloses its reference label", statement A is the compound statement as shown above. I believe the goto statement is enclosed within statement A, and statement A directly-encloses the reference label (L3).
The MISRA C 2012 and MISRA C 2023 versions of the equivalent rule 15.3 provide a different amplification that directly addresses this: "A switch-clause that does not consist of a compound statement is treated as if it were a block"
Please let me know what you think. Thank you.