title: Why NRVO is not applied here?
body: <p>NRVO is not applied when I run this code in VS2010.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  class A
  {
      public:
  
      A() { printf( "I am in constructor\n" ); }
      A(const A&amp; a) { printf( "I am in copy constructor\n" ); }
      ~A() { printf( "I am in destructor\n" ); }
      int i;       
  };
  
  A f(int j)
  {
      A a;
      if ( j )  return a;
      a.i = j;
      return a; 
  }
  
  int main()
  {
      A a;
      a = f(5);
  }
  </code></pre>
  
  <p><strong>Edit: this has something to do with the destructor. When I comment out its line, NRVO is used. But why is this?</strong></p>