title: Is it undefined behaviour to have a reference to freed memory?
body: <p>In C++, is it undefined behaviour to free memory that is still referred to by a reference, even if that reference is not used again? For example, does the following function invoke undefined behaviour?</p>
  
  <pre><code>void foo() {
      std::map&lt;std::string, int&gt; mymap;
      {
          int&amp; val = mymap["eight"];
          val = 8;
          mymap.erase("eight"); // Oops! val still refers to mymap["eight"]
          // val is not used again
      }
      std::cout &lt;&lt; "Entry count: " &lt;&lt; mymap.size() &lt;&lt; "\n";
  }
  </code></pre>