title: std::bind to a std::function crashes with Clang
body: <p>I'm having trouble understanding some subtleties when combining std::bind with std::function.</p>
  
  <p>I have minimized my problems to the following code snippet:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  
  void bar(int x) {
      std::cout &lt;&lt; "Hello." &lt;&lt; std::endl;
  }
  
  int main(int argc, char* argv[])
  {
      std::function&lt;void(int)&gt; f1 = std::bind(bar, std::placeholders::_1);
  
      // CRASHES with clang, works fine in VS2010 and VS2012
      std::function&lt;void()&gt; f2 = std::bind(f1, 1);
  
      f2();
  
      return 0;
  }
  </code></pre>
  
  <p>Note the explicit conversion to std::function&lt;> (replacing <code>std::function&lt;void()&gt;</code> with <code>auto</code> when constructing <code>f2</code> works fine).</p>
  
  <p>Creating <code>f2</code> by copying the <code>f1</code> object crashes with Clang on OS X (XCode 5.0.1, OS X 10.9 SDK), but works fine with VS2010/VS2012. After a hideously long callstack, the code crashes with a EXC_BAD_ACCESS - note this is when <em>constructing</em> the function object, not when calling it.</p>
  
  <p><strong>Is this a bug in the library implementation or a problem with my code?</strong></p>
  
  <p>A workaround is to explicitly call the <code>operator ()</code> member, like this:</p>
  
  <pre><code>std::function&lt;void()&gt; f2 =
      std::bind(&amp;std::function&lt;void(int)&gt;::operator(), f1, 1);
  </code></pre>
  
  <p>but this comes with a caveat, as it fails to compile on VS2012 (but works in VS2010). This seems to be <a href="https://stackoverflow.com/a/14842371/227322">a bug with VS2012</a>.</p>