title: const reference to a temporary object becomes broken after function scope (life time)
body: <p>While asking <a href="https://stackoverflow.com/questions/15267676/reference-to-an-unnamed-temporary-object-life-time">this question</a>, I learned const reference to a temporary object is valid in C++:</p>
  
  <pre><code>int main ()
  {
    int a = 21;
    int b = 21;
  
    //error: invalid initialization of non-const reference
    //int     &amp; sum = a + b;e [...]
  
    //OK
    int const &amp; sum = a + b;
  
    return sum;
  }
  </code></pre>
  
  <p>But in the following example, the const reference <code>refnop</code> refers to a destroyed temporary object. I wonder why?</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;map&gt;
  
  struct A
  {
     // data 
     std::map &lt;std::string, std::string&gt;  m;
     // functions
     const A&amp; nothing()           const { return *this;    }
     void init()                        { m["aa"] = "bb";  }
     bool operator!= (A const&amp; a) const { return a.m != m; }
  };
  
  int main()
  {
    A a;
    a.init();
  
    A const&amp; ref    = A(a);
    A const&amp; refnop = A(a).nothing();
  
    int ret = 0;
    if (a != ref)     ret += 2;
    if (a != refnop)  ret += 4;
  
    return ret;
  }
  </code></pre>
  
  <p>Tested using GCC 4.1.2 and MSVC 2010, it returns 4;</p>
  
  <pre><code>$&gt; g++ -g refnop.cpp
  $&gt; ./a.out ; echo $?
  4
  </code></pre>
  
  <p>The difference between <code>ref</code> and <code>refnop</code> is the call to <code>nothing()</code> which does really nothing. It seems after this call, the temporary object is destroyed!</p>
  
  <p>My question: <br>
  <strong>Why in the case of <code>refnop</code>, the life time of the temporary object is not the same as its const reference?</strong></p>