File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 15
15
16
16
import cpp
17
17
import codingstandards.c.misra
18
+ import codingstandards.c.misra.EssentialTypes
18
19
19
- from ControlFlowNode expr , string message
20
+ from Expr expr , string message
20
21
where
21
22
not isExcluded ( expr , Statements5Package:: controllingExprInvariantQuery ( ) ) and
22
23
(
35
36
exists ( Loop loop |
36
37
loop .getControllingExpr ( ) = expr and
37
38
(
38
- conditionAlwaysFalse ( expr )
39
+ conditionAlwaysFalse ( expr ) and
40
+ not (
41
+ getEssentialTypeCategory ( getEssentialType ( expr ) ) instanceof EssentiallyBooleanType and
42
+ expr .getValue ( ) = "0"
43
+ )
39
44
or
40
45
conditionAlwaysTrue ( expr ) and
41
46
// Exception allows for infinite loops, but we only permit that for literals like `true`
Original file line number Diff line number Diff line change @@ -22,8 +22,13 @@ void f2() {
22
22
}
23
23
24
24
void f3 () {
25
- while (true) { // Permitted by exception
25
+ while (true) { // COMPLIANT - permitted by exception 1
26
26
}
27
27
while (1 < 2 ) { // NON_COMPLIANT - likely an indication of a bug
28
28
}
29
+ }
30
+
31
+ void f4 () {
32
+ do {
33
+ } while (0u == 1u ); // COMPLIANT - by exception 2
29
34
}
You can’t perform that action at this time.
0 commit comments