<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:hhinnant@apple.com" title="Howard Hinnant <hhinnant@apple.com>"> <span class="fn">Howard Hinnant</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - std::function return type cannot automatically cast to void"
   href="http://llvm.org/bugs/show_bug.cgi?id=16633">bug 16633</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - std::function return type cannot automatically cast to void"
   href="http://llvm.org/bugs/show_bug.cgi?id=16633#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - std::function return type cannot automatically cast to void"
   href="http://llvm.org/bugs/show_bug.cgi?id=16633">bug 16633</a>
              from <span class="vcard"><a class="email" href="mailto:hhinnant@apple.com" title="Howard Hinnant <hhinnant@apple.com>"> <span class="fn">Howard Hinnant</span></a>
</span></b>
        <pre>This is a feature, not a bug.  The example violates [func.wrap.func]/p2 and p7
which require the functor to be Callable for argument types ArgTyeps and return
type R.  The definition of Callable requires the result of the functor to be
implicitly convertible to R.

But:

    static_assert(!std::is_convertible<bool, void>::value, "");

which is specified in [meta.rel]/p4.

The violation of this requirement results in undefined behavior, meaning
anything can happen.  It is legal for the implementation to compile and execute
the code.  It is legal for the implementation to refuse to compile it.

libc++ used to compile and execute this code.  However that was causing
problems too.  For example this SO question:

<a href="http://stackoverflow.com/questions/5931214/isnt-the-template-argument-the-signature-of-stdfunction-part-of-its-type">http://stackoverflow.com/questions/5931214/isnt-the-template-argument-the-signature-of-stdfunction-part-of-its-type</a>

complains of an ambiguity.  The ambiguity can be resolved by eliminating the
function(F) constructor when F is not Callable.

It is possible that a future standard may require this behavior:

<a href="http://cplusplus.github.io/LWG/lwg-closed.html#1024">http://cplusplus.github.io/LWG/lwg-closed.html#1024</a>

Here is one way to work around this requirement:

    std::function<void ()> fns = [](){std::bind(fn, true)();};</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>