|
1 | 1 | /** |
2 | 2 | * @id c/misra/goto-label-block-condition |
3 | | - * @name RULE-15-3: Any label referenced by a goto statement shall be declared in the same block, or in any block |
| 3 | + * @name RULE-15-3: The goto statement and any of its label shall be declared or enclosed in the same block. |
4 | 4 | * @description Any label referenced by a goto statement shall be declared in the same block, or in |
5 | 5 | * any block enclosing the goto statement |
6 | 6 | * @kind problem |
7 | | - * @precision very-high |
8 | | - * @problem.severity error |
| 7 | + * @precision high |
| 8 | + * @problem.severity recommendation |
9 | 9 | * @tags external/misra/id/rule-15-3 |
| 10 | + * maintainability |
| 11 | + * readability |
10 | 12 | * external/misra/obligation/required |
11 | 13 | */ |
12 | 14 |
|
13 | 15 | import cpp |
14 | 16 | import codingstandards.c.misra |
15 | 17 |
|
16 | | -from |
| 18 | +from GotoStmt goto |
17 | 19 | where |
18 | | - not isExcluded(x, Statements2Package::gotoLabelBlockConditionQuery()) and |
19 | | -select |
| 20 | + not isExcluded(goto, Statements2Package::gotoLabelBlockConditionQuery()) and |
| 21 | + not goto.getEnclosingBlock+() = goto.getTarget().getEnclosingBlock() |
| 22 | + or |
| 23 | + exists(SwitchStmt switch, int caseLocation, int nextCaseLocation | |
| 24 | + switch.getAChild*() = goto and |
| 25 | + switch.getASwitchCase().getLocation().getStartLine() = caseLocation and |
| 26 | + switch.getASwitchCase().getNextSwitchCase().getLocation().getStartLine() = nextCaseLocation and |
| 27 | + goto.getLocation().getStartLine() > caseLocation and |
| 28 | + goto.getLocation().getStartLine() < nextCaseLocation and |
| 29 | + ( |
| 30 | + goto.getTarget().getLocation().getStartLine() < caseLocation |
| 31 | + or |
| 32 | + goto.getTarget().getLocation().getStartLine() > nextCaseLocation |
| 33 | + ) and |
| 34 | + goto.getTarget().getLocation().getStartLine() > switch.getLocation().getStartLine() |
| 35 | + ) |
| 36 | +select goto, "The $@ statement and its $@ are not declared or enclosed in the same block.", goto, |
| 37 | + "goto", goto.getTarget(), "label" |
0 commit comments