Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement (MISRA 6-6-1)
Unconstrained use of goto can lead to programs that are extremely difficult to comprehend, analyse and, for C++, can also lead to the program exhibiting unspecified behaviour.
However, in many cases a total ban on goto requires the introduction of flags to ensure correct control flow, and it is possible that these flags may themselves be less transparent than the goto they replace.
Therefore, the restricted use of goto is allowed where that use will not lead to semantics contrary to developer expectations. Jumping in to nested blocks is prohibited as it may lead to complex flow graphs.
- Violation message
Move the label referenced by this goto statement outside of current block
- Default priority