When compiling the following code in Visual Studio 2019 while using the "C++ Core Check Lifetime Rules", I get "warning C26486: Don't pass a pointer that may be invalid to a function. Parameter 0 '@vA' in call to 'std::vector<'LifeTimeWarning'::'2'::XY,std::allocator<'LifeTimeWarning'::'2'::XY> >::push_back' may be invalid (lifetime.3).":
struct XY { int c1; };
vector<XY> vA, vB;
vA.push_back({1});
vB.push_back(vA.at(0));
The warning disappears, if I replace the struct-type with a simple integer, or if I assign vA.at(0) to a temporary variable, and then push back the variable to vB. Why is that? Also, how is this code "unsafe" in the first place?