MISRAC2012-Rule-15.2
In this section:
Synopsis
(Required) The goto statement shall jump to a label declared later in the same function
Enabled by default
Yes
Severity/Certainty
Low/Low

Full description
A goto statement is declared after the destination label. This check is identical to MISRAC++2008-6-6-2, MISRAC++2023-9.6.3.
Coding standards
- MISRA C++ 2008 6-6-2
(Required) The goto statement shall jump to a label declared later in the same function body.
- MISRA C++ 2023 9.6.3
(Required) The goto statement shall jump to a label declared later in the function body
Code examples
The following code example fails the check and will give a warning:
void f1 ( )
{
int j = 0;
for ( j = 0; j < 10 ; ++j )
{
L1: // Non-compliant
j;
}
goto L1;
}
The following code example passes the check and will not give a warning about this issue:
void f1 ( )
{
int j = 0;
goto L1;
for ( j = 0; j < 10 ; ++j )
{
j;
}
L1:
return;
}