title: binding a temporary object to a const reference
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int f() 
  {
      int x=1;
      return x;
  }
  
  int main()
  {
      const int&amp; s = f();
      cout &lt;&lt; s &lt;&lt; endl;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int x=1;
  
  int &amp;f() 
  {
      return x;
  }
  
  int main()
  {
      const int&amp; s = f();
      cout &lt;&lt; s &lt;&lt; endl;
  }
  </code></pre>
  
  <hr>
  
  <p>Both of these programs are correct. But when I use</p>
  
  <pre><code>int &amp;f() 
  {
      int x=1;
      return x;
  }
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>int f() 
  {
      int x=1;
      return x;
  }
  </code></pre>
  
  <p>I get an error:</p>
  
  <p>main.cpp: In function 'int&amp; f()':</p>
  
  <p>main.cpp:6:13: warning: reference to local variable 'x' returned [-Wreturn-local-addr]</p>
  
  <pre><code>     int x=1;
  
           ^
  </code></pre>
  
  <p>bash: line 7: 14826 Segmentation fault      (core dumped) ./a.out</p>
  
  <p>What's wrong?</p>