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

Johannes Schaub (litb) schaub.johannes at googlemail.com
Sun May 22 05:57:23 PDT 2011


Richard Smith wrote:

> 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.
> 

Hi! Is this program not ill-formed? Clang accepts it without moaning, 
silently choosing the second "f":

template<typename T>
struct A;
typedef A<int> aint;

void f(aint);
void f(...) { }

int main() {
  f(0);
}

But the FDIS says that if the completeness of A<int> might affect the 
semantics of the program, it is instantiated. 

The FDIS says if the implicit instantiation of a class template 
specialization is required, but the class template is only declared but not 
defined, the program is ill-formed (14.7.1p7).





More information about the cfe-dev mailing list