fghj
fghj

Reputation: 9394

VS C++ 2012(13) can not convert overloaded-function to std::function

I have such code:

#include <functional>

struct Foo {
    template<typename T>
    static void f(int);
};

template<>
void Foo::f<int>(int) {}

int main()
{
    std::function<void(int)> func;
//func = static_cast<void (*)(int)>(Foo::f<int>);/works
    func = Foo::f<int>;//compilation failure
    return 0;
 }

VS 2012 and 2013 Preview give compile time error at line:

func = Foo::f<int>;//compilation failure

error C3867: Foo::f: in function call no argument list, use "&Foo::f" to create pointer to member

error C2440: =: can not convert "overloaded-function" into "std::function"

But gcc 4.8.1, clang 3.3 and Intel Compiler 13.1.3 compile this code with options (-Wall -pedantic -std=c++11) without any warnings and errors.

So is this compiler bug of C++ compiler of Visual Studio?

Upvotes: 0

Views: 225

Answers (1)

Jesse Good
Jesse Good

Reputation: 52365

Yes, it is a bug, visual studio 2013 rc compiles this without a problem so it looks like they have fixed it.

Upvotes: 1

Related Questions