MISRAC++2023-9.6.2
In this section:
Synopsis
(Required) The goto statement shall jump to a label declared later in the function body
Enabled by default
Yes
Severity/Certainty
Low/Low

Full description
The destination of a goto statement is a nested code block. This check is identical to MISRAC++2008-6-6-1, MISRAC2012-Rule-15.3.
Coding standards
- MISRA C:2012 Rule-15.3
(Required) Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement
- MISRA C++ 2008 6-6-1
(Required) Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement.
Code examples
The following code example fails the check and will give a warning:
void f1 ( )
{
int j = 0;
goto L1;
for (;;)
{
L1: // Non-compliant
j;
}
}
The following code example passes the check and will not give a warning about this issue:
void f2()
{
for(;;)
{
for(;;)
{
goto L1;
}
}
L1:
return;
}