MISRA Discussion Forums

Full Version: Rule 3-9-2 and operator overloading
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear MISRA team,

according to ISO/IEC 14882:2003 chapter 13.5.7 a single int is required to distinguish between prefix and postfix operators:

Code:
class X {
public:
X& operator++(); // prefix ++a
X operator++(int); // postfix a++
};

If you recategorize 3-9-2 as mandatory would the usage of int require a deviation or is it an explicit exception (compare with int main exception in DIR 4.6 of MISRA C 2012) ?
Thanks.
At the moment this rule does apply to these overloads, so would require a deviation. This is under review of the next version
misra cpp Wrote:At the moment this rule does apply to these overloads, so would require a deviation. This is under review of the next version
I am struggling with finding a good reason for the deviation as defined in chapter 4.4 of MISRA Compliance 2016.
I currently would choose
Quote:Usability (Recognizability)
because it´s basically about recognizing operator overloading as defined in ISO C++ 2003.
Do you agree?
Thanks.
We'd say the reason to deviate is to ensure compliance with rule 1-0-1 (All code shall comply with the C++ standard), which in this case requires the use of int

In terms of MISRA compliance, we'd suggest Compatibility covers this