MISRAC++2023-13.3.4 (C++ only)
In this section:
Synopsis
(Required) A comparison of a potentially virtual pointer to member function shall only be with nullptr
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
The result of such a comparison with anything else is unspecified.
Coding standards
This check does not correspond to any coding standard rules.
Code examples
The following code example fails the check and will give a warning:
class A
{
public:
void f();
virtual void g();
};
void example( void ( A::*ptr )() )
{
if ( ptr == &A::f ) {} // Non-compliant - ptr potentially points to A::g,
// which is virtual
}
The following code example passes the check and will not give a warning about this issue:
class A
{
public:
void f();
virtual void g();
};
void example( void ( A::*ptr )() )
{
if ( ptr == nullptr ) {} // Compliant
}