http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334

--- Comment #47 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-31 
16:42:27 UTC ---
21.4.1 [string.require] says that the non-const forms of operator[], at, front,
back, begin, rbegin, end and rend may not invalidate references, pointers and
iterators (so must not reallocate or modify the string)

This example shows that requirement is not met:

    std::string s("str");
    const char* p = s.data();
    {
        std::string s2(s);
        (void) s[0];
    }
    std::cout << *p << '\n';  // p is dangling

Also the copy constructor requirements in Table 64 require the new object to
have a copy of the data.  I think there are other reasons too.

Reply via email to