title: Warning C4172: Returning a reference to const std::string bound to a local variable. How safe is it?
body: <p>I was just building one of our projects at work and I see a new function was added:</p>
  
  <pre><code>const std::string&amp; ClassName::MethodName() const
  {
     return "";
  }
  </code></pre>
  
  <p>The compiler gives a warning:</p>
  
  <blockquote>
    <p>Warning C4172: returning address of local variable or temporary</p>
  </blockquote>
  
  <p>I think the compiler is right. <strong><em>How safe is this function?</em></strong></p>
  
  <p>Note that the function doesn't return <code>const char*</code> which would be OK inasmuch as string literals have static storage duration. It returns a reference to <code>const std::string</code></p>