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.
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 |