MISRA Discussion Forums
Is rule 7-5-3 really relevant? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.7 Declarations (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=136)
+---- Thread: Is rule 7-5-3 really relevant? (/showthread.php?tid=828)



Is rule 7-5-3 really relevant? - triboix - 27-05-2011

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


Re: Is rule 7-5-3 really relevant? - misra cpp - 05-10-2015

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