07-04-2017, 10:59 AM
dg1980 Wrote:As soon as you store a reference, it becomes class data.
To me that's not clear from the definition of "class data" (as mentioned in the original post). And this is exactly the question I'm asking MISRA to confirm.
The same goes with a resource that's not allocated by the constructor or released by the destructor, but pointed to by a pointer member.
Note the definition of "class data" actually made clear that static members are not "class data", and in the example the resource reference by `b` could be shared by multiple objects and acts basically the same as a static member.
Quote:I slightly reworked the example, to make it even more obvious what evil code you could write, if this was not treated a violation of 9-3-1:
The evilness of your code does not come from not following 9-3-1, but from the fact that a member referencing a shared object (with automatic storage). Removing `const` from `getB` and some other functions will make the code 9-3-1 compliant (under your interpretation) but doesn't really make it less evil.
<t></t>