Qt-Autosar-A5.10.1¶
A pointer to member virtual function shall only be tested for equality with null-pointer-constant
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
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¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
check_class_types¶
check_class_types : bool = False
require_nullptr¶
require_nullptr : bool = False