Unexpected behavior when using std::vector with move semantics in C++20
I'm confused about I'm experiencing unexpected behavior when I attempt to move elements from a `std::vector` in C++20. I have a vector of objects that contain a `std::string`, and I want to transfer ownership of these objects to another collection using move semantics. I expected the original vector to be empty after the move, but it appears that some objects are still accessible and not properly moved out. Here's a simplified version of my code: ```cpp #include <iostream> #include <vector> #include <string> class Test { public: std::string data; Test(std::string str) : data(std::move(str)) {} void display() const { std::cout << data << std::endl; } }; int main() { std::vector<Test> vec; vec.emplace_back("Hello"); vec.emplace_back("World"); std::vector<Test> vec2 = std::move(vec); for (const auto& item : vec) { item.display(); // This shows unexpected output } return 0; } ``` I expected that after the move, `vec` would not contain valid `Test` objects, yet when I try to access them, the program runs without crashing and displays corrupted data. I'm compiling with g++ 11.2 with C++20 support enabled. Is this expected behavior when moving objects from a vector, or am I missing a critical step in how move semantics works with `std::vector`? Any insights would be greatly appreciated! Any ideas what could be causing this? I'm working on a service that needs to handle this. Cheers for any assistance!