<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - std::function return type cannot automatically cast to void"
   href="http://llvm.org/bugs/show_bug.cgi?id=16633">16633</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::function return type cannot automatically cast to void
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tatraian@deverto.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I wrote the following c++ code:

#include <functional>

using namespace std;

bool fn(bool t){
    return t;
}


int main(int argc, char** argv){
    std::function<void ()> fns = std::bind(fn, true);
    return 0;
}


This code can be compiled with g++ 4.7 with libstdc++ and clang (trunk
-r186306) also with libstdc++. But I cannot compile with libc++ (trunk -r
186237) I got the next error message:

tatraian@server09:~/Pilots$ clang++ -std=c++11 -stdlib=libc++ -lc++abi
-nostdinc++ -I/home/tatraian/llvm-svn-libcxx/include/c++/v1 
-L/home/tatraian/llvm-svn-libcxx/lib/
-L/home/tatraian/tmp/llvm-svn-libcxxabi/lib/ bind.cc
bind.cc:11:28: error: no viable conversion from '__bind<bool (&)(bool), bool>'
to 'std::function<void ()>'
    std::function<void ()> fns = std::bind(fn, true);
                           ^     ~~~~~~~~~~~~~~~~~~~
/home/tatraian/llvm-svn-libcxx/include/c++/v1/functional:1138:5: note:
candidate constructor not viable: no known
      conversion from '__bind<bool (&)(bool), bool>' to 'nullptr_t' for 1st
argument
    function(nullptr_t) _NOEXCEPT : __f_(0) {}
    ^
/home/tatraian/llvm-svn-libcxx/include/c++/v1/functional:1139:5: note:
candidate constructor not viable: no known
      conversion from '__bind<bool (&)(bool), bool>' to 'const
std::__1::function<void ()> &' for 1st argument
    function(const function&);
    ^
/home/tatraian/llvm-svn-libcxx/include/c++/v1/functional:1140:5: note:
candidate constructor not viable: no known
      conversion from '__bind<bool (&)(bool), bool>' to
'std::__1::function<void ()> &&' for 1st argument
    function(function&&) _NOEXCEPT;
    ^
/home/tatraian/llvm-svn-libcxx/include/c++/v1/functional:1144:41: note:
candidate template ignored: disabled by
      'enable_if' [with _Fp = std::__1::__bind<bool (&)(bool), bool>]
                                        __callable<_Fp>::value &&
                                        ^ 

I think libc++' function takes care about return type. But I don't know if this
behaviour comes from C++ standard, or the standard says nothing about it or
just simply a bug.

In other way, it is logical that implicit cast does not work, but is there a
standard way to create a function object from an other function object that
differs only in return type (it changes return type to void)?</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>