title: Undefined behavior and temporaries
body: <p>1) Is it undefined behavior to return a reference to a temporary, even if that reference is not used? For example, is this program guaranteed to output "good":</p>
  
  <pre><code>int&amp; func()
  {
      int i = 5;
      return i;
  }
  
  int main()
  {
      func();
  
      cout &lt;&lt; "good" &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>2) Is it undefined behavior to simply have a reference to an object that no longer exists, even if that reference is not used? For example, is this program guaranteed to output "good":</p>
  
  <pre><code>int main()
  {
      int *j = new int();
      int &amp;k = *j;
      delete j;
  
      cout &lt;&lt; "good" &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>3) Is it undefined behavior to combine these?</p>
  
  <pre><code>int&amp; func()
  {
      int i = 5;
      return i;
  }
  
  int main()
  {
      int&amp; p = func();
  
      cout &lt;&lt; "good" &lt;&lt; endl;
      return 0;
  }
  </code></pre>