[LLVMbugs] [Bug 22003] New: Calling `std::__bind` (a returned function object of `std::bind`) makes unnecessary instantiation of function templates

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Dec 22 05:31:31 PST 2014


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

            Bug ID: 22003
           Summary: Calling `std::__bind` (a returned function object of
                    `std::bind`) makes unnecessary instantiation of
                    function templates
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mimomorin at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

Created attachment 13586
  --> http://llvm.org/bugs/attachment.cgi?id=13586&action=edit
fix and test case

A function template with deduced return type needs to be instantiated to 
deduce its return type. If the instantiation is ill-formed, this results in 
hard errors. 

This code (line 1866 in <functional>), which is evaluated when calling
`std::__bind` 
(a returned function object of `std::bind`), 

    typename enable_if
    <
        is_bind_expression<_Ti>::value,
        typename __invoke_of<_Ti&, _Uj...>::type
    >::type

might unnecessarily instantiate `Ti`'s `operator()` and cause errors. 
For example, if `Ti` is the type of `[](auto x) { return x.value; } and `Uj` is
`int`, 
we get errors. Here is a full source code to get errors: 

    #include <functional>
    struct binary_func
    {
        template<typename S, typename T>
        void operator()(S&&, T&&) const {}
    };
    int main(int argc, char* argv[])
    {
        auto bind = std::bind(
            binary_func()
          , [](auto x) { return x.value; } // Note: no SFINAE
          , std::placeholders::_1
        );
        bind(0); // Error
    }

We can avoid this unnecessary instantiations by replacing `enable_if` in the
code above 
with `__lazy_enable_if`. 

Patch attached.

-- 
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/20141222/7c3dfb46/attachment.html>


More information about the llvm-bugs mailing list