AUTOSAR C++14 Rule A7-5-2
Functions shall not call themselves, either directly or indirectly
Description
Rule Definition
Functions shall 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: Declaration |
Category: Required, Automated |
Version History
Introduced in R2019a