We're not sure what distinction you are making between 1 & 2 - but they are basically the behaviour we require: A is non-compliant, B & C are compliant.
Basically we want to prevent returning a pointer/reference to a subobject of the class, whose lifetime may be longer than that of the object.
We also want to avoid the need for pointer tracing, so we're not interested in the source of B::ptr or what is subsequently done with the value returned by B::Get
Thanks for highlighting a real issue. We've noted that the wording of this rule may need clarification in the next issue.
Basically we want to prevent returning a pointer/reference to a subobject of the class, whose lifetime may be longer than that of the object.
We also want to avoid the need for pointer tracing, so we're not interested in the source of B::ptr or what is subsequently done with the value returned by B::Get
Thanks for highlighting a real issue. We've noted that the wording of this rule may need clarification in the next issue.
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group