OROT -- Overwrite Related Operators Together
Go Up to C++ Audits
Description
Certain operators should be overloaded together with their related matches, or should not be overloaded at all. For instance, overloading only the new operator without overloading delete can crash your application.
The OROT audit checks for the following pairs of overloaded operators and raises a violation when one member of a pair, but not both, is overloaded. You can choose which pairs of related operators to check for by selecting them on the options panel. By default, they are all selected.
Pairs of opposite operators that can be audited:
==
and!=
+
and+=
-
and-=
new
anddelete
Incorrect
class LinkedListIterator {
public:
bool operator== (LinkedListIterator i) const;
...
};
Correct
class LinkedListIterator {
public:
bool operator== (LinkedListIterator i) const;
bool operator!= (LinkedListIterator i) const;
...
};