MISRA Discussion Forums

Full Version: Is rule 7-5-3 really relevant?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Is rule 7-5-3 really relevant?

It says that something like
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:
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!

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++.