title: Why can std::function be constructed with a lambda with a different return type?
body: <p>The following <a href="http://melpon.org/wandbox/permlink/aO3eLLNUYZ3ucxcx" rel="noreferrer">compiles fine</a>:</p>
  
  <pre><code>#include &lt;functional&gt;
  
  int main()
  {
      std::function&lt;const int&amp;()&gt; f = []() -&gt; int {return 1;};
      const int&amp; r = f(); // r is a dangling reference
      return 0;
  }
  </code></pre>
  
  <p>How come it's possible to set an <code>std::function</code> with a <code>const int&amp;</code> return type to a lambda with an <code>int</code> return type? Allowing this sort of cast to happen implicitly and with no warning is a gotcha IMHO.</p>