Rule 0-1-11 and postfix increment/decrement operators

Moderators: david ward, misra cpp

Post Reply
Posts: 9
Joined: Tue May 01, 2018 9:34 am
Company: TomTom

Rule 0-1-11 and postfix increment/decrement operators

Post by rrosier » Thu Nov 19, 2020 4: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:
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: Select all

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.

Posts: 117
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

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

Post by dg1980 » Thu Nov 19, 2020 6:42 pm

Search for 0-1-11 in ... elines.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.

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

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

Post by misra cpp » Wed Dec 02, 2020 3:29 pm

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
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.0 Language independent issues (C++)”