[cfe-dev] Compile error with libc++'s bind

Richard Smith richard at metafoo.co.uk
Sat May 21 14:45:17 PDT 2011


Hi Jonathan,

> the following program fails to compile with clang trunk and libc++ trunk
> (note the implicit conversion from <const char*>
> to <std::string> when calling the functor in <doIt>):
>
> #include <functional>
>
> using namespace std::placeholders;
>
> template <typename Functor> static void doIt(Functor f) {
> f(""); }
>
>
> static void method(const std::string&);	// A //static void method(const
> char*);	// B
>
> int main(int, char**) {
> doIt(std::bind(&method, _1));
> }

You're missing the #include <string>. It appears that <functional> is
pulling in a forward-declaration of it, but that's not enough for clang to
know that an implicit conversion from const char* exists.

Regards,
Richard





More information about the cfe-dev mailing list