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: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs