MISRA C++:2008 Rule 6-6-5
A function shall have a single point of exit at the end of the function
Description
Rule Definition
A function shall have a single point of exit at the end of the function.1
Rationale
This rule requires that a return
statement must occur as the
last statement in the function body. Otherwise, the following issues can occur:
Code following a
return
statement can be unintentionally omitted.If a function that modifies some of its arguments has early
return
statements, when reading the code, it is not immediately clear which modifications actually occur.
Polyspace Implementation
The checker flags these situations:
A function has more than one
return
statement.A non-
void
function has onereturn
statement only but thereturn
statement is not the last statement in the function.
A void
function need not have a return
statement. If a return
statement exists, it need not be the last
statement in the function.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Check Information
Group: Statements |
Category: Required |
Version History
Introduced in R2013b1 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.