Rule A5-10-1 (required, implementation, automated)

A pointer to member virtual function shall only be tested for equality with null-pointer-constant.

Rationale

The result of equality comparison between pointer to member virtual function and anything other than null-pointer-constant (i.e. nullptr, see: A4-10-1) is unspecified.

Example

// $Id: A5-10-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $ class A { public: virtual ~A() = default; void F1() noexcept {} void F2() noexcept {} virtual void F3() noexcept {} }; void Fn() { bool b1 = (&A::F1 == &A::F2); // Compliant bool b2 = (&A::F1 == nullptr); // Compliant bool b3 = (&A::F3 == nullptr); // Compliant bool b4 = (&A::F3 != nullptr); // Compliant bool b5 = (&A::F3 == &A::F1); // Non-compliant }

See also

HIC++ v4.0 [9]: 5.7.2 Ensure that a pointer to member that is a virtual function is only compared (==) with nullptr.

JSF December 2005 [8]: AV Rule 97.1 Neither operand of an equality operator (== or !=) shall be a pointer to a virtual member function.