title: C++ anonymous string destruction time
body: <p>We have a function <code>GetString()</code> that returns a <code>std::string</code>.  We then have a function <code>ConsumeString(char*)</code> that consumes a C-style string.</p>
  <p>Is it a bug to write <code>ConsumeString(GetString().c_str())</code>?  To me it looks like this would be a bug because after <code>c_str()</code> runs, the original anonymous string will get destructed and you'll have a pointer to something that doesn't exist anymore.  But weirdly, it always seems to work fine.</p>
  <p>I only noticed it could be an issue when I tried to assign <code>GetString().c_str()</code> to a variable and then use it in two separate <code>ConsumeString()</code> functions, at which point it printed a corrupted string and the problem became obvious.  But I don't know why it seems to work in the former case.</p>
  <p>Is it potentially a bug that just happens to work, or does C++ specifically allow this?</p>