+ 1

std::move visual studio warning?

A colleague of mine said that using move in Visual Studio gave a warning like “use of a moved from object: …”. Can someone please run the MWE in visual studio below and confirm if this happens? If the warning does come up, any suggestions? https://code.sololearn.com/cPHA2z6JXvID/?ref=app

30th Sep 2022, 2:03 PM
Edward Finkelstein
Edward Finkelstein - avatar
1 ответ
+ 4
While I can't test the code in Visual Studio, the warning would be valid since you're using 'y' which had been moved into 'z'. While this has no conquences on std::string, some other class might have a move constructor that leaves the moved-from object unusable if you're not aware of what operations are valid on them. A simple example would be moving a unique_ptr and using it without realising that a move-from unique_ptr stores a null pointer. Related thread on SO https://stackoverflow.com/questions/7027523/what-can-i-do-with-a-moved-from-object
1st Oct 2022, 6:04 PM
XXX
XXX - avatar