Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is rule 7-5-3 really relevant?
#1
Hello,

Is rule 7-5-3 really relevant?

It says that something like
Code:
int& f(int& x)
{
    return x;
}
is not compliant.

But surely all C++ developers on the planet would expect x to be modified here after calling f:
Code:
void f(int& x)
{
    x++;
}

So why returning x directly would be an issue? I guess there is probably something I am not seeing here!

Thanks for any clarification!

Fabrice
<t></t>
Reply
#2
7-5-3 is important for const references where a copy may be created. Non-conforming compilers in use when MISRA C++:2008 was developed also had the same behaviour for non-const objects.

We will review this guideline in the next version of MISRA C++.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)