AUTOSAR C++14 Rule M7-5-2
The address of an object with automatic storage shall not be assigned to another object that may persist after the first object has ceased to exist
Since R2020b
Description
Rule Definition
The address of an object with automatic storage shall not be assigned to another object that may persist after the first object has ceased to exist.
Rationale
If an object continues to point to another object after the latter object ceases to exist, dereferencing the first object leads to undefined behavior.
Polyspace Implementation
Polyspace® reports a violation of this rule if you assign the address of an automatic storage object to an object with greater lifetime. Objects with greater lifetime include:
Global pointer variables
Local objects declared at an outer scope
The checker does not raise violations of this rule if a function returns the address of
a local variable. AUTOSAR C++14 Rule
M7-5-1
covers this situation.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Declaration |
Category: Required, Non-automated |
Version History
Introduced in R2020b