5 Expressions [expr]

5.10 Equality operators [expr.eq]

equality-expression:
    relational-expression
    equality-expression == relational-expression
    equality-expression != relational-expression

The == (equal to) and the != (not equal to) operators have the same semantic restrictions, conversions, and result type as the relational operators except for their lower precedence and truth-value result. [ Note: a<b == c<d is true whenever a<b and c<d have the same truth-value.  — end note ] Pointers of the same type (after pointer conversions) can be compared for equality. Two pointers of the same type compare equal if and only if they are both null, both point to the same function, or both represent the same address ([basic.compound]).

In addition, pointers to members can be compared, or a pointer to member and a null pointer constant. Pointer to member conversions ([conv.mem]) and qualification conversions ([conv.qual]) are performed to bring them to a common type. If one operand is a null pointer constant, the common type is the type of the other operand. Otherwise, the common type is a pointer to member type similar ([conv.qual]) to the type of one of the operands, with a cv-qualification signature ([conv.qual]) that is the union of the cv-qualification signatures of the operand types. [ Note: this implies that any pointer to member can be compared to a null pointer constant.  — end note ] If both operands are null, they compare equal. Otherwise if only one is null, they compare unequal. Otherwise if either is a pointer to a virtual member function, the result is unspecified. Otherwise they compare equal if and only if they would refer to the same member of the same most derived object ([intro.object]) or the same subobject if they were dereferenced with a hypothetical object of the associated class type. [ Example:

struct B {
  int f();
};
struct L : B { };
struct R : B { };
struct D : L, R { };

int (B::*pb)() = &B::f;
int (L::*pl)() = pb;
int (R::*pr)() = pb;
int (D::*pdl)() = pl;
int (D::*pdr)() = pr;
bool x = (pdl == pdr);          // false

 — end example ]

If two operands of type std::nullptr_t are compared, the result is true if the operator is ==, and false otherwise.

Each of the operators shall yield true if the specified relationship is true and false if it is false.