I currently am migrating a large code base from
- Visual Studio 2013 (v120)
- C++11
to
- Visual Studio 2019 (v142)
- C++17
and now, my tests fail in strange places - I get index out of bounds crashes and other strange changes in behavior. Upon digging I noticed that the following code:
#include <iostream>
#include <vector>
int main()
{
std::vector<std::vector<int>> nestedVector;
nestedVector.insert(nestedVector.begin(), {});
std::cout << nestedVector.size() << " elements";
}
produces a one-element vector in VS2013 but an empty vector in VS2019.
Other ways of inserting
nestedVector.insert(nestedVector.begin(), std::vector<int>{});
nestedVector.insert(nestedVector.begin(), std::vector<int>());
work in both setups and properly add a new element. What is happening here?