-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:This goto statement must be replaced by a standard iteration statement.
-
Default Severity:Blocker
-
Impact:High
-
Likelihood:High
-
Default Quality Profiles:Sonar way
-
Legacy Key:BackJumpWithGoto, BackwardsGoto
-
Covered Languages:C, C++, Objective-C, PL/SQL
-
Remediation Function:Constant/Issue
-
Constant Cost:1h
-
PC-Lint:9064
Unconstrained use of goto can lead to programs that are extremely difficult to comprehend and analyse. For C++, it can also lead to the program exhibiting unspecified behavior.
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. "Back" jumps are prohibited, since they can be used to create iterations without using the well-defined iteration statements supplied by the core language.
Noncompliant Code Example
int f() { int j = 0; L1: ++j; if (10 == j) { goto L2; // forward jump ignored } // ... goto L1; // Noncompliant L2: return ++j; }
Compliant Solution
int f() { for (int j = 0; j < 11; j++) { // ... } return ++j; }
- is implemented by
-
CPP-174 Rule MISRA 6-6-2 : The goto statement shall jump to a label declared later in the same function body
-
- Closed
-
-
CPP-707 Create Objective-C rules repository containing targeted rules
-
- Closed
-
- relates to
-
RSPEC-1064 PL/SQL: GOTO should not be used to jump backwards
- Active
1.
|
PL/SQL: GOTO should not be used to jump backwards | RSPEC-1064 |
|
Active | Unassigned | |
2.
|
C-Family | RSPEC-4353 |
|
Active | Unassigned |