Skip to main content

IAR Embedded Workbench for Arm 9.70.x

LOGIC-overload (C++ only)

In this section:
Synopsis

Overloaded && and || operators

Enabled by default

No

Severity/Certainty

Low/Low

lowlow.png
Full description

There are overloaded versions of the comma and logical conjunction operators with the semantics of function calls, whose sequence point and ordering semantics are different from those of the built- in versions. It might not be clear at the point of use that these operators are overloaded, and which semantics that apply. This check is identical to MISRAC++2008-5-2-11_a, MISRAC++2023-16.5.1.

Coding standards
MISRA C++ 2008 5-2-11

(Required) The comma operator, && operator and the || operator shall not be overloaded.

MISRA C++ 2023 16.5.1

(Required) The logical AND and logical OR operators 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;
}