Let's take this simplified example:
std::vector< int > v;
v.push_back( 1 );
v.insert( v.end()-1, v[ v.size()-1 ] ); // the problem is on this line
// We output the vector
std::for_each( v.begin(), v.end(), []( const int& e_ ){ std::cout<<e_<<std::endl; } );
output:
-17891602
1
The author of the code intended to insert a duplicate of the last element before the end of the vector. There are several good ways to to this but the author decided to use this one.
It worked as "expected" before C++11. That is because in the microsoft implementation of the insert in a vector, they make a copy of the value to insert in case the value inserted is in the range of the vector.
Now with C++11, there is a version of insert taking a r-value reference which do not need to do this trick because it's a temporary anyway.
But surprisingly, using the code above, the compiler decides to take the r-value ref version instead of the by-reference version, which inserts a uninitialized value before the end of the vector. Note that the operator[] returns by reference.
Why does the compiler chose to take the version by r-value reference?