Skip to content

Commit 745d04c

Browse files
committed
Rule 16.7: Use the essential type
Relational operations do not have boolean type in C, so we need to use the essential type library to identify them.
1 parent 501e8da commit 745d04c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

c/misra/src/rules/RULE-16-7/SwitchExpressionBoolCondition.ql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
import cpp
1515
import codingstandards.c.misra
16-
import codingstandards.cpp.SwitchStatement
16+
import codingstandards.c.misra.EssentialTypes
1717

18-
from BooleanSwitchStmt switch
19-
where not isExcluded(switch, Statements2Package::switchExpressionBoolConditionQuery())
20-
select switch, "The condition of this $@ statement has boolean type", switch, "switch"
18+
from SwitchStmt switch, Expr controllingExpr
19+
where
20+
not isExcluded(switch, Statements2Package::switchExpressionBoolConditionQuery()) and
21+
controllingExpr = switch.getControllingExpr() and
22+
getEssentialTypeCategory(getEssentialType(controllingExpr)) = EssentiallyBooleanType()
23+
select controllingExpr, "The condition of this $@ statement has boolean type", switch, "switch"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.c:16:11:16:17 | ... == ... | The condition of this $@ statement has boolean type | test.c:16:3:24:3 | switch (...) ... | switch |
2+
| test.c:28:11:28:24 | ... == ... | The condition of this $@ statement has boolean type | test.c:28:3:36:3 | switch (...) ... | switch |

0 commit comments

Comments
 (0)