Below code
std::vector< std::string > v07 = { { "1", "2" } };
is equivalent to
std::string s = {"1","2"}; // call string(const char*, const char*)
std::vector<std::string> v07 = {s}; // initializer list with one item
the issue is with
s={"1","2"};
This calls string(const char* start, const char* end)
constructor,
but start
and end
must refer to the same string object. “1” and “2” are two different objects, so it leads to UB.