![]() |
|
Rule 6.8.4 clarification of amplification - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188) +---- Forum: 4.6 Basic concepts (https://forum.misra.org.uk/forumdisplay.php?fid=192) +---- Thread: Rule 6.8.4 clarification of amplification (/showthread.php?tid=1747) |
Rule 6.8.4 clarification of amplification - kth - 08-08-2025 The amplification of rule 6.8.4 leads with this sentence to clarify to which member functions this rule applies: Quote:This rule applies to member functions with reference or pointer return type, where, in the definition of the function, at least one The usage of the word “designates” here is ambiguous. Does it mean the expression . . .
Depending on which interpretation is true, the following code examples are either compliant or non-compliant: Code: class A {The intent of the rule seem to support meaning number 2, which would mean only A::Get is non-compliant. If that is the case, we suggest to replace “designates” with a less ambiguous phrase, e.g. “references/points to” or to explain more clearly what is meant in the amplification. In addition, clarifying examples for these cases would be helpful. RE: Rule 6.8.4 clarification of amplification - misra cpp - 24-08-2025 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. |