Boost C++ Libraries: Ticket #12893: Add debug check for boost::container::string::c_str method https://svn.boost.org/trac10/ticket/12893 <p> If boost::container::string was destroyed then result of c_str method must be invalidated. It will help to catch errors in a application. </p> <p> Notes: </p> <ol><li>std::string on MS Visual Studio 2015 is already does this check. </li><li>some patterns are here <a class="ext-link" href="http://stackoverflow.com/a/127404"><span class="icon">​</span>http://stackoverflow.com/a/127404</a> </li></ol><p> Example: </p> <pre class="wiki">#include &lt;cassert&gt; #include &lt;string&gt; #include &lt;boost/container/string.hpp&gt; bool isAbcd(const char* ch) { if ( ch[0] == 'a' &amp;&amp; ch[1] == 'b' &amp;&amp; ch[2] == 'c' &amp;&amp; ch[3] == 'd' &amp;&amp; ch[4] == '\0' ) { return true; } return false; } void exampleNewDelete() { char* ch = new char[5]; ch[0] = 'a'; ch[1] = 'b'; ch[2] = 'c'; ch[3] = 'd'; ch[4] = '\0'; assert(isAbcd(ch)); delete[] ch; const bool ok = isAbcd(ch); // if app crash then test OK if ( ok ) { assert(false); // test failed } // test OK } void exampleStdString() { char* ch; ch = (char*)std::string("abcd").c_str(); const bool ok = isAbcd(ch); // if app crash then test OK if ( ok ) { assert(false); // test failed } // test OK } void exampleBoostString() { char* ch; ch = (char*)boost::container::string("abcd").c_str(); const bool ok = isAbcd(ch); // if app crash then test OK if ( ok ) { assert(false); // test failed } // test OK } int main() { //exampleNewDelete(); //exampleStdString(); //exampleBoostString(); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12893 Trac 1.4.3