<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::bind result can't be used in SFINAE context"
   href="http://llvm.org/bugs/show_bug.cgi?id=15295">15295</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::bind result can't be used in SFINAE context
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.2
          </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>enhancement
          </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>amanieu@gmail.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>The following code tries to detect whether a function object can be called with
an int argument or no arguments.

#include <functional>
#include <iostream>

// Detect whether the function takes an int argument or zero arguments
template<typename T, typename = decltype(std::declval<T>()(0))> std::true_type
detect_type(const T&);
template<typename T, typename = decltype(std::declval<T>()())> std::false_type
detect_type(const T&);

int main()
{
    auto a = std::bind([](int){}, std::placeholders::_1); // Prints 1
    //auto a = std::bind([](){}, std::placeholders::_1); // Prints 0
    std::cout << decltype(detect_type(a))::value << std::endl;
}

This works fine in libstdc++ but in libc++ it fails with the following error:

In file included from libc++_bind_bug.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:594:
In file included from /usr/include/c++/v1/utility:125:
/usr/include/c++/v1/__tuple:160:5: error: static_assert failed "tuple_element
index out of range"
    static_assert(_Ip != 0, "tuple_element index out of range");
    ^             ~~~~~~~~
/usr/include/c++/v1/tuple:206:22: note: in instantiation of template class
'std::__1::tuple_element<0, std::__1::__tuple_types<> >' requested here
    typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
                     ^
/usr/include/c++/v1/functional:1605:22: note: in instantiation of template
class 'std::__1::tuple_element<0, std::__1::tuple<> >' requested here
    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
                     ^
/usr/include/c++/v1/functional:1623:14: note: in instantiation of template
class 'std::__1::____mu_return<std::__1::placeholders::__ph<1>, false, false,
true, std::__1::tuple<> >' requested here
    : public ____mu_return<_Ti,
             ^
/usr/include/c++/v1/functional:1640:18: note: in instantiation of template
class 'std::__1::__mu_return<std::__1::placeholders::__ph<1>, std::__1::tuple<>
<span class="quote">>' requested here</span >
        typename __mu_return
                 ^
/usr/include/c++/v1/functional:1724:18: note: in instantiation of template
class 'std::__1::__bind_return<<lambda at libc++_bind_bug.cpp:10:21>,
std::__1::tuple<std::__1::placeholders::__ph<1> >, std::__1::tuple<> >'
requested here
        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
                 ^
/usr/include/c++/v1/functional:1725:9: note: while substituting deduced
template arguments into function template 'operator()' [with _Args = <>]
        operator()(_Args&& ...__args)
        ^
libc++_bind_bug.cpp:6:80: note: in instantiation of default argument for
'detect_type<std::__1::__bind<<lambda at libc++_bind_bug.cpp:10:21>,
std::__1::placeholders::__ph<1> &> >' required here
template<typename T, typename = decltype(std::declval<T>()())> std::false_type
detect_type(const T&);
                                                                              
^~~~~~~~~~~~~~~~~~~~~
libc++_bind_bug.cpp:6:80: note: while substituting deduced template arguments
into function template 'detect_type' [with T = std::__1::__bind<<lambda at
libc++_bind_bug.cpp:10:21>, std::__1::placeholders::__ph<1> &>, $1 = <no
value>]
template<typename T, typename = decltype(std::declval<T>()())> std::false_type
detect_type(const T&);

The problem seems to be that calling the result of bind can't be used in a
SFINAE context.</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>