title: Lambda captures unexpected variables
body: <p>I was trying to figure out how lambda works in C++.</p>
  
  <p>And something strange happened. It's so weird that I don't know how to describe it correctly. I tried googling several keywords, but didn't find anything mentioned the behavior.</p>
  
  <p>I first tried <a href="https://ideone.com/zy0vEg" rel="nofollow">this code</a>.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;utility&gt;
  using namespace std ;
  
  auto func() {
      int a = 0 ;
  
      auto increase = [ &amp;a ]( int i = 1 ){ a += i ; } ;
      auto print = [ &amp;a ](){ cout &lt;&lt; a &lt;&lt; '\n' ; } ;
  
      pair&lt; decltype(increase), decltype(print) &gt; 
      p = make_pair( increase, print ) ;
      return p ;
  }
  
  int main() {
      auto lambdas = func() ;
  
      auto increase = lambdas.first ;
      auto print = lambdas.second ;
  
      print() ;
      increase() ;
      print() ;
      increase( 123456 ) ;
      print() ;
  
      return 0;
  }
  </code></pre>
  
  <p>The output is as expected as</p>
  
  <pre><code>-1218965939
  -1218965938
  -1218842482
  </code></pre>
  
  <p>However, after I add this into the 'func()' </p>
  
  <pre><code>cout &lt;&lt; typeid( decltype( print ) ).name() &lt;&lt; '\n'
       &lt;&lt; typeid( decltype( increase ) ).name() &lt;&lt; '\n' ;
  </code></pre>
  
  <p>like <a href="http://ideone.com/5shIHv" rel="nofollow">this one</a></p>
  
  <p>the output became</p>
  
  <pre><code>Z4funcvEUlvE0_
  Z4funcvEUliE_
  0
  1
  123457
  </code></pre>
  
  <p>I did not expect to happen.</p>
  
  <p>[UPDATE] </p>
  
  <p>The variable <code>a</code> should have be "dead" because its life-cycle was ended.</p>
  
  <p>But I'm curious why the code exams <code>typeid</code> and <code>decltype</code> cause <code>a</code> seemed to be resurrected?</p>