MISRA C:2012 Rule 14.3
Controlling expressions shall not be invariant
描述
规则定义
Controlling expressions shall not be invariant 1 .
理由
如果控制表达式(例如 if
条件)具有常量值,则不变的值可能指向编程错误。
Polyspace 实现
如果控制语句的控制表达式始终为 true
或 false
,则检查项会报告违规。Polyspace® 检查的控制语句包括:
if
,switch
for
,while
,do-while
三元 (
?:
) 运算符
Polyspace Bug Finder™ 通过死代码和无用的 if 条件检查项标记一些违反 MISRA C™ 14.3 的情形。
故障排除
如果您预计存在违规,但未看到该违规,请参阅Diagnose Why Coding Standard Violations Do Not Appear as Expected。
示例
检查信息
组:控制语句表达式 |
类别:必需 |
AGC 类别:必需 |
版本历史记录
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.