MISRA C++:2008 Rule 7-5-4
Functions should not call themselves, either directly or indirectly
Description
Note
Using Code Prover for checking coding rules is no longer supported. See Version History.
Rule Definition
Functions should not call themselves, either directly or indirectly.
Rationale
Variables local to a function are stored in the call stack. If a function calls itself directly or indirectly several times, the available stack space can be exceeded, causing serious failure. Unless the recursion is tightly controlled, it is difficult to determine the maximum stack space required.
Polyspace Implementation
The checker reports each function that calls itself, directly or indirectly. Even if several functions are involved in one recursion cycle, each function is individually reported.
You can calculate the total number of recursion cycles using the code complexity
metric Number of Recursions
. Note that unlike
the checker, the metric also considers implicit calls, for instance, to
compiler-generated constructors during object creation.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Declarations |
Category: Advisory |