Is rule 7-5-3 really relevant?

Moderators: david ward, misra cpp

Post Reply
Posts: 3
Joined: Fri May 27, 2011 10:19 am
Company: Falcon One Ltd

Is rule 7-5-3 really relevant?

Post by triboix » Fri May 27, 2011 11:24 am


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!


misra cpp
Posts: 161
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

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

Post by misra cpp » Mon Oct 05, 2015 3:00 pm

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

Post Reply

Return to “6.7 Declarations (C++)”