6 ms·
A move constructor is supposed to leave the donor object in a valid state. All STL objects with one will do so. If you write a poor move constructor that doesn
by jdsully 7y ago
A move constructor is supposed to leave the donor object in a valid state. All STL objects with one will do so.
If you write a poor move constructor that doesn’t do this you will get exactly what you asked for. However the compiler has no way to know you half assed it and must support a legal valid case.
See this stack overflow: https://stackoverflow.com/questions/9168823/reusing-a-moved-container https://stackoverflow.com/questions/9168823/reusing-a-moved-...
To quote office space, “Your moved from object only needs to be destructible. But some people choose to allow more and we encourage that.”
- comex 7y ago"if (x = y)" is also a legal valid use case (it sets x to y, and then tests whether it's nonzero), but that doesn't stop compilers from complaining if you write it, on the grounds that it's most likely a mistake. They should do the same with use-after-move. There could then be some workaround or annotation to disable the warning if you really did want a use-after-move, as there is for the warning I mentioned (adding extra parentheses).