Immediately make a reservation, the question is purely theoretical, without practical application. 3 code examples:
one)
std::string s = "abc"; char& c = s[0]; c = 'A'; // OK, s == "Abc" 2)
std::string s = "abc"; char& c = s[0]; s += "def"; c = 'A'; // Error: UB, s+="def" 'kill' c reference 3)
std::string s = "abc"; s.reserve(100); char& c = s[0]; s += "def"; c = 'A'; // ??? OK (s == "Abcdef") or UB??? Quote from Josattis "Standard C ++ Library. Reference Guide":
In order to avoid mistakes ... you should reserve enough capacity before the link is initialized ...
Actually, the question is, from the point of view of the C ++ 11 standard. Is the 3rd sample code correct? (from the point of view of style - bad, I understand).