Qt-Autosar-A5.10.1

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

Required inputs: IR

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.

Possible Messages

Key

Text

Severity

Disabled

member_virtual_function_comparison

Comparison of a member virtual function with non-nullptr.

None

False

Options

check_class_types

check_class_types : bool = False

Check class for virtual methods that may match a comparison argument.
 

require_nullptr

require_nullptr : bool = False

Disallow the integer 0 as null pointer literal.