MISRAC++2008-6-6-1
In this section:
Synopsis
(Required) Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement.
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 MISRAC2012-Rule-15.3, MISRAC++2023-9.6.2.
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++ 2023 9.6.2
(Required) A goto statement shall reference a label in a surrounding block
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;
}