AutosarC++19_03-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

Required inputs: IR

Rationale

If the address of an automatic object is assigned to another automatic object of larger scope, or to a static object, or returned from a function, then the object containing the address may exist beyond the time when the original object ceases to exist (and its address becomes invalid).

Note that throwing a pointer to an object with automatic storage is also a violation of this rule.

Example
void foobar ( void ) 
{
int8_t * p1;
{
int8_t local_auto;
p1 = &local_auto; // Non-compliant
}
}

Note

For legal reasons, this rule’s description is not part of the public documentation.