include::../description.adoc[]

== Noncompliant Code Example

----
void f1 (int a) {
  if (a <=0) {
    goto L2;  // Noncompliant; jumps into a different block
  }

  if (a == 0) {
  {
    goto L1; // Compliant
  }
  goto L2;  // Noncompliant; jumps into a block

L1:
  for (int i = 0; i < a; i++) {
  L2:
    //...  Should only have come here with a >=0. Loop is infinite if a < 0
  }
}
----

== Compliant Solution

----
void f1 (int a) {
  if (a <=0) {
    // ...
  }

  if (a == 0) {
  {
    goto L1; // Compliant
  }

L1:
  for (int i = 0; i < a; i++) {
  L2:
    //...  
  }
}
----

== See

* MISRA {cpp}:2008, 6-6-1 - Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement
* MISRA C:2012, 15.3 - Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
