MISRA C:2023 Rule 17.4
R2026bAll exit paths from a function with non-void return type shall have an explicit return statement with an expression
自 R2024a 起
描述
All exit paths from a function with non-void return type shall have an explicit return statement with an expression 1 .
理由
如果非 void 函数没有显式返回值,但调用该函数却使用了返回值,则该行为是未定义的。为了防止此行为,必须遵守以下要求:
必须提供带显式表达式的
return语句。必须确保在运行时至少有一个
return语句执行。
作为例外,如果使用 C99 或更高版本的标准,main() 函数中缺少显式 return 语句是合规的。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:函数 |
| 类别:强制 |
| AGC 类别:强制 |
PQL 名称:std.misra_c_2023.R17_4 |
版本历史记录
在 R2024a 中推出
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:2025
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.