19-11-2020, 04:29 PM
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:
Such operators are then written as:
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.
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.
<t></t>