This comment is incorrect.
Instead of providing your own move constructor if you want the compiler to provide one, one of the requirements is that it expects the destructor to be provided to them too, i.e. trivial destructor. However, the current standard is pretty strict when an implicit implementation can be provided - in accepting how the user gives the destructor. Everything that is declared by the user is considered that the user takes matters into their own hands and, therefore, not only this
~A() { โฆ }
but this one
~A() = default;
causes the compiler not to provide an implicit destructor. Firstly, it is a definition and, therefore, a declaration; the second is just a declaration. In both cases, the destructor is declared by the user and thus prevents the compiler from providing an implicit move constructor.
I believe that the rationale for the requirement is that during the move, the resource of the object is moved to another object, leaving the original object in a state where it does not have resources in dynamic storage; but if your class does not have such resources, then it can be trivially moved, destroyed, etc. When you declare a non-trivial destructor, itโs key for the compiler that the resources you manage in the class are not trivial and that you basically would need to provide a nontrivial move, so the compiler does not provide it.
legends2k Jun 20 '13 at 19:05 2013-06-20 19:05
source share