MISRAC++2023-16.5.1
In this section:
Synopsis
(Required) The logical AND and logical OR operators shall not be overloaded
Enabled by default
Yes
Severity/Certainty
Low/Low

Full description
Overloaded && and || operators were found. This check is identical to LOGIC-overload, MISRAC++2008-5-2-11_a.
Coding standards
- MISRA C++ 2008 5-2-11
(Required) The comma operator, && operator and the || operator shall not be overloaded.
Code examples
The following code example fails the check and will give a warning:
class C{
bool x;
bool operator||(bool other);
};
bool C::operator||(bool other){
return x || other;
}
The following code example passes the check and will not give a warning about this issue:
class C{
int x;
int operator+(int other);
};
int C::operator+(int other){
return x + other;
}