Finds comparison operators(==, !=, <, <=, >, >=) which are not
noexcept, are defined as member functions, have parameters of different type
or pass parameters not by value for cheap to copy types and not by reference to
const for expensive to copy types.
Examples:
struct A { int Var; bool operator==(const A &a) const; // 'operator==' should not be member function };
struct B; bool operator==(const B &lh, const B &rh); // 'operator==' should be marked noexcept
struct C; bool operator==(const C &lh, int rh) noexcept; // 'operator==' should have 2 parameters of the same type
struct C { // cheap to copy int Var; }; bool operator==(const C &lh, const C &rh) noexcept; // 'lh' of type 'C' is cheap to copy, should be passed by value // 'rh' of type 'C' is cheap to copy, should be passed by value
struct D { // expensive to copy int Array[1024]; }; bool operator==(D lh, D rh) noexcept; // 'lh' of type 'D' is expensive to copy, should be passed by reference to const // 'rh' of type 'D' is expensive to copy, should be passed by reference to const
Options:
- CheckParamPassing
Boolean flag to warn when operators pass parameters not by value for cheap to copy types and not by reference to const for expensive to copy types. Default value is true.
- ExpensiveToCopySize
When parameters have a size greater than ExpensiveToCopySize bytes, treat them as expensive to copy types. Default value is 0, which means to use 2 * sizeof(void*) as the threshold.
The relevant rules in the C++ Core Guidelines are:
Is there a precedent to match spaceship operator?