[LLVMbugs] [Bug 15295] New: std::bind result can't be used in SFINAE context

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Feb 18 15:30:52 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=15295

            Bug ID: 15295
           Summary: std::bind result can't be used in SFINAE context
           Product: libc++
           Version: 3.2
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: hhinnant at apple.com
          Reporter: amanieu at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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<>
>' requested here
        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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130218/fe7852ac/attachment.html>


More information about the llvm-bugs mailing list