MISRA Discussion Forums
Rule 3-9-2 and operator overloading - 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.3 Basic concepts (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=132)
+---- Thread: Rule 3-9-2 and operator overloading (/showthread.php?tid=1354)



Rule 3-9-2 and operator overloading - dg1980 - 30-06-2017

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.


Re: Rule 3-9-2 and operator overloading - misra cpp - 12-07-2017

At the moment this rule does apply to these overloads, so would require a deviation. This is under review of the next version


Re: Rule 3-9-2 and operator overloading - dg1980 - 17-10-2017

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.


Re: Rule 3-9-2 and operator overloading - misra cpp - 17-01-2018

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