AutosarC++18_03-M5.3.3

The unary & operator shall not be overloaded

Required inputs: IR

Programmers expect operator && and operator || to have short-circuiting behavior. As it is impossible for user-defined overloads of these operators to have the expected behavior, these operators should never be overloaded.

The built-in operator , introduces a "sequence before" relation between the left and right operands. However, user-defined operator overloads act like functions, and thus prior to C++17 do not have a defined sequence relation between their arguments. While in C++17 and later the arguments are sequenced to match the built-in operator, overloaded operator , may not match programmer expectations and should therefore be avoided.

Programmers expect the address-of operator operator & to return the address of its operand. User-defined overloads can lead to surprising behavior and should be avoided.

Bad code:
class S {
public:
    bool operator&&(const S& other) const; // ERROR: Do not overload operator&&.
    bool operator||(const S& other) const; // ERROR: Do not overload operator||.
    bool operator,(const S& other) const; // ERROR: Do not overload operator,.
    S *operator&() const; // ERROR: Do not overload operator&.
};

Note

For legal reasons, this rule’s description is not part of the public documentation.