Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is Fn4 example in AUTOSAR rule A7-5-2 correct?
#1
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?
Reply
#2
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.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)