Rule 3-9-2 and operator overloading

Moderators: david ward, misra cpp

Post Reply
dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Rule 3-9-2 and operator overloading

Post by dg1980 » Fri Jun 30, 2017 10:01 am

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: Select all

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.

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

Re: Rule 3-9-2 and operator overloading

Post by misra cpp » Wed Jul 12, 2017 2:13 pm

At the moment this rule does apply to these overloads, so would require a deviation. This is under review of the next version
Posted by and on behalf of
the MISRA C++ Working Group

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

Re: Rule 3-9-2 and operator overloading

Post by dg1980 » Tue Oct 17, 2017 1:19 pm

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
Usability (Recognizability)
because it´s basically about recognizing operator overloading as defined in ISO C++ 2003.
Do you agree?
Thanks.

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

Re: Rule 3-9-2 and operator overloading

Post by misra cpp » Wed Jan 17, 2018 4:18 pm

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

Post Reply

Return to “6.3 Basic concepts (C++)”