MISRA Discussion Forums
Is Fn4 example in AUTOSAR rule A7-5-2 correct? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185)
+--- Thread: Is Fn4 example in AUTOSAR rule A7-5-2 correct? (/showthread.php?tid=1776)



Is Fn4 example in AUTOSAR rule A7-5-2 correct? - limdor - 02-07-2026

AUTOSAR rule A7-5-2 has the following example:
Code:
std::int32_t Fn4(std::int32_t number)
{
  if (number == 1)
  {
    number = number * Fn3(number - 1);  // Non-compliant
  }   
  return number;
}
Fn3 is a recursive function and thus non-compliant. Fn4 is making a call to Fn3. However, in this line, the function is not calling itself. Why is this line Non-compliant? Is this an issue with the example?


RE: Is Fn4 example in AUTOSAR rule A7-5-2 correct? - misra cpp - 03-07-2026

We'd agree that Fn4 should not be marked as non-compliant, as it doesn't call itself (directly or indirectly).

Autosar C++:2014 has effectively been replaced by MISRA C++:2023. This has an equivalent rule 8.2.10 "Functions shall not call themselves, either directly or indirectly". It's examples do not have this problem.