[Bug libstdc++/21334] Lack of Posix compliant thread safety in std::basic_string

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu May 31 17:19:00 GMT 2012


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.



More information about the Gcc-bugs mailing list