MISRA Discussion Forums
Rule A12-8-4 and default constructing data members in a move constructor - 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: Rule A12-8-4 and default constructing data members in a move constructor (/showthread.php?tid=1622)



Rule A12-8-4 and default constructing data members in a move constructor - Albin - 15-06-2022

Quoting the rationale of this A12-8-4:
Quote:Data members or base classes initialization in move constructor needs to be done with move semantics.
Does this mean that in order to comply with the rule, all data members in a move constructor must be initialized with move semantics, and thus no data members may be default constructed in a move constructor?
The text of the rule does not go that far, it merely prevents the use of copy semantics in move constructors.


RE: Rule A12-8-4 and default constructing data members in a move constructor - Albin - 16-06-2022

I should add some additional context. In a constructor, we want to construct a data member in the constructor member initializer list, and the move assign to it in the function body of the constructor. Is this in compliance with the rule or is it breaking the rule because the data member is not initialized using move semantics?


RE: Rule A12-8-4 and default constructing data members in a move constructor - misra cpp - 17-06-2022

We agree the intent of 12-8-4 was to prevent calls made to copy constructors and/or copy assignment operators, so you are compliant.

However, what you are proposing violates the spirit of the rationale for 12-8-4, and may be a violation of other rules.