Page 1 of 1

Is rule 7-5-3 really relevant?

Posted: Fri May 27, 2011 11:24 am
by triboix

Is rule 7-5-3 really relevant?

It says that something like

Code: Select all

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: Select all

void f(int& 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!


Re: Is rule 7-5-3 really relevant?

Posted: Mon Oct 05, 2015 3:00 pm
by misra cpp
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++.