AUTOSAR C++14 Rule M6-4-2
R2026bAll if ... else if constructs shall be terminated with an else clause
描述
All if ... else if constructs shall be terminated with an else clause.
理由
以 else 语句结束 if... else if 构造是一种防御性编程。这个最终的 else 语句起到故障安全机制的作用,以防出现代码执行越过 if 和 else if 语句的特殊情况。
当一个 if 语句后面跟着一个或多个 else if 语句时,在最后一个 else if 语句后添加一个 else 语句。在 else 语句内提供一个操作。如果无需执行任何操作,提供一条注释,说明不执行操作的原因。
Polyspace 实现
只要 if … else if 构造没有以 else 语句结尾,Polyspace® 就会报告此缺陷。
故障排除
如果您预期会出现违规,而 Polyspace 未报告该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:语句 |
| 类别:必需、自动 |
PQL 名称:std.autosar_cpp14.M6_4_2 |
版本历史记录
在 R2019a 中推出