[cfe-users] Trouble understanding reason for Clang error - std::bind/std::function issue
Adam Nielsen via cfe-users
cfe-users at lists.llvm.org
Sat May 7 05:31:11 PDT 2016
> I am having some issues compiling my own code which works with GCC but
> fails using Clang, and I can't work out why. I am hoping that someone
> here might be able to tell me whether it is an issue with my code or
> a bug in Clang.
I'm still confused by this, but I've been able to produce a small
self-contained example that demonstrates the problem:
=====
#include <functional>
bool example_bool(int a, int b)
{
return false;
}
void example_void(int a, int b)
{
return;
}
void main2()
{
typedef std::function<void(int)> fn;
// This works
fn v = std::bind<void>(example_void, std::placeholders::_1, 123);
// This doesn't work
fn b = std::bind<void>(example_bool, std::placeholders::_1, 123);
}
=====
The "fn v" line works, but the "fn b" line fails:
no known conversion from '__bind_r<void, bool (&)(int, int),
std::__1::placeholders::__ph<1> &, int>' to
'std::__1::function<void (int)> &&' for 1st argument
How should I be doing this so that Clang accepts the code?
> $ clang --version
> Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
> Target: x86_64-apple-darwin13.4.0
Thanks,
Adam.
More information about the cfe-users
mailing list