Qt-Autosar-A5.5.1¶
A pointer to member shall not access non-existent class members
Required inputs: IR, StaticSemanticAnalysis
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Usage of a pointer-to-member expression leads to undefined behavior in the following cases:
- The pointer to member is a null pointer.
- The dynamic type of the object does not contain the member to which the called pointer to member refers.
Example
// $Id: A5-5-1.cpp 302200 2017-12-20 17:17:08Z michal.szczepankiewicz $
class A
{
public:
virtual ~A() = default;
};
class AA : public A
{
public:
virtual ~AA() = default;
virtual void foo() { }
using ptr = void (AA::*)();
};
class B
{
public:
static AA::ptr foo_ptr2;
};
AA::ptr B::foo_ptr2;
int main(void)
{
A* a = new A();
void (A::*foo_ptr1)() = static_cast<void(A::*)()>(&AA::foo);
(a->*foo_ptr1)(); // non-compliant
delete a;
AA* aa = new AA();
(aa->*B::foo_ptr2)(); // non-compliant, not explicitly initialized
delete aa;
return 0;
}
See Also
- SEI CERT C++ Coding Standard [10]: OOP55-CPP: Do not use pointer-to- member operators to access nonexistent members
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
non-existing |
Calling a non-existing member via a pointer-to-member call. |
None |
False |
uninitialized |
Uninitialized pointer-to-member called. |
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
pointer_target_limit¶
pointer_target_limit : int | None = 5