title: lambda: should capturing const reference by reference yield undefined behaviour?
body: <p>I just found a nasty bug in my code because I captured a const reference to a string by reference. By the time the lambda was run the original string object was already long gone and the referenced value was empty whereas the purpose was that it would contains the value of the original string, hence the bug. </p>
  
  <p>What baffles me is that this did not invoke a crash at runtime: after all, shouldn't this be undefined behaviour since afaik there is a dangling reference? Moreover when looking at id under the debugger, it doesn't even look like garbage but just like a properly constructed empty string.</p>
  
  <p>Here's the test case; this just prints an empty line:</p>
  
  <pre><code>typedef std::vector&lt; std::function&lt; void() &gt; &gt; functions;
  
  void AddFunction( const std::string&amp; id, functions&amp; funs )
  {
    funs.push_back( [&amp;id] ()
      {
          //the type of id is const std::string&amp;, but there
          //is no object to reference. UB?
        std::cout &lt;&lt; id &lt;&lt; std::endl;
      } );
  }
  
  int main()
  {
    functions funs;
    AddFunction( "id", funs );
    funs[ 0 ]();
  }
  </code></pre>