title: Template function causes a compiler error when used with local lambda
body: <p>My <a href="https://stackoverflow.com/questions/6809890/c0x-lambda-for-makecontext-argument-2">previous question</a> concluded that a distasteful "double cast" might be necessary to use the POSIX <code>makecontext</code> with a C++ lambda function (i.e. function object). Moving on, I'm now faced with a compilation error relating to the following minimal code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ucontext.h&gt;
  
  using namespace std;
  
  template &lt;typename T&gt; void foo()   {
    ucontext_t c;
    auto f = [=](int i){ cout &lt;&lt; i &lt;&lt; endl; };
    makecontext(&amp;c, (void (*) (void)) (void (*)(int)) f, 1, 12345);
  }
  
  int main(int argc, char *argv[]) {
    foo&lt;int&gt;();
    return 0;
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>error: invalid cast from type ‘foo() [with T = int]::&lt;lambda(int)&gt;’ to type ‘void (*)(int)’
  </code></pre>
  
  <p>However, if I remove the unused (in this example) template argument from the <code>foo</code> function, so it becomes <code>void foo();</code>, and change the call to <code>foo()</code> the error disappears. Could someone tell me why? I'm using G++ 4.6.</p>
  
  <p>Edit:</p>
  
  <p>From the comments below, it seems the <code>[=]</code> in the code above causes the lambda to be a "capturing" lambda, regardless of the fact that it doesn't actually capture anything. The <code>[=]</code> is not necessary in my code, alas replacing with <code>[]</code> in GCC 4.6 does not remove the error. I am installing GCC 4.6.1 now...</p>