MISRA C:2012 Rule 17.4
All exit paths from a function with non-void return type shall have an explicit return statement with an expression
Description
Rule Definition
All exit paths from a function with non-void return type shall have an explicit return statement with an expression1 .
Rationale
If a non-void
function does not explicitly return a value but the calling
function uses the return value, the behavior is undefined. To prevent this behavior:
You must provide
return
statements with an explicit expression.You must ensure that during run time, at least one
return
statement executes.
As an exception, lacking an explicit return
statement in your main()
function is compliant with this rule if
you use C99 or later.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Function |
Category: Mandatory |
AGC Category: Mandatory |
Version History
Introduced in R2014bSee Also
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.