MISRA Discussion Forums
A8-4-5: are partial moves allowed? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185)
+--- Thread: A8-4-5: are partial moves allowed? (/showthread.php?tid=1709)



A8-4-5: are partial moves allowed? - cgpzs - 01-10-2024

Are partial moves allowed by A8-4-5? If not, why not?

For example, consider the following snippet from Effective Modern C++ (Meyers), Item 25, page 169:

Code:
class Widget {
public:
   Widget(Widget&& rhs)
   : name(std::move(rhs.name)),
     p(std::move(rhs.p))
   { … }
   …

// rhs is rvalue reference
private:
   std::string name;
   std::shared_ptr<SomeDataStructure> p;
};



RE: A8-4-5: are partial moves allowed? - misra cpp - 22-10-2024

We have to agree that the Autosar rule is unclear on this subject.

We agree your example doesn't have any undesirable behaviour, but if the rule were to explicitly allow that, it would also have to say something about code that only moves a subset of the members, say 'name', but not 'p'