MISRA Discussion Forums
Rule 0-1-11 and postfix increment/decrement operators - 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.0 Language independent issues (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=129)
+---- Thread: Rule 0-1-11 and postfix increment/decrement operators (/showthread.php?tid=1554)



Rule 0-1-11 and postfix increment/decrement operators - rrosier - 19-11-2020

Rule 0-1-11 states that there shall be no unused parameters (named or unnamed) in a non-virtual function.

However, when writing a postfix increment/decrement operator, the C++ standard states:

Quote:If the function is a member function with one parameter (which shall be of type int) or a non-member function with two parameters (the second of which shall be of type int), it defines the postfix increment operator ++ for objects of that type.
...
The prefix and postfix decrement operators -- are handled analogously.

Such operators are then written as:

Code:
struct X {
  X operator++(int); // postfix a++
};

On the face of it, this seems to violate Rule 0-1-11, because the unnamed int parameter is unused.

Is this an real violation, so that in order to write postfix increment/decrement operators we have to deviate, or is this rule not intended to apply in such cases where the C++ standard itself is defining that the parameter is unused (and therefore any flagging of such code is a false positive)?

I cannot find any direct prohibition of the writing of postfix increment/decrement operators elsewhere in the MISRA rules, so it surprises me that this rule appears to prohibit their use in this roundabout fashion.


Re: Rule 0-1-11 and postfix increment/decrement operators - dg1980 - 19-11-2020

Search for 0-1-11 in https://www.autosar.org/fileadmin/user_upload/standards/adaptive/19-11/AUTOSAR_RS_CPP14Guidelines.pdf.
See what they did there?
But for MISRA C++ 2008 you would need a deviation permit as this case is not listed as exception in the standard itself.


Re: Rule 0-1-11 and postfix increment/decrement operators - misra cpp - 02-12-2020

We are aware of this issue and are considering for the next version of MISRA C++

The most likely outcome is that postfix increment/decrement will be made an except to the rule, so no deviation would be required