MISRA C++:2023 Rule 6.8.1
Description
Rule Definition
An object shall not be accessed outside of its lifetime.
Rationale
The lifetime of an object starts after it is initialized and ends at the end of its scope, even if the memory occupied by the object is not released. Accessing an object before its lifetime begins and after its lifetime ends results in undefined behavior.
Specific and trivial instances of lifetime violations are covered by MISRA C++:2023 Rule
6.8.2
and MISRA C++:2023 Rule
6.8.3
. Other lifetime violations are covered by this rule.
Polyspace Implementation
Polyspace® reports a violation if you access:
A block of memory after freeing the block using the
free
function or thedelete
operatorAn object after its destructor is invoked
A nonactive union member
An unnamed temporary object by reference after the unnamed temporary object goes out of scope
Polyspace does not report taking the address of a nonactive union member as a violation of this rule.
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: Basic concepts |
Category: Required |
Version History
Introduced in R2024b