Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::async decaying(losing) rvalue reference in Visual Studio 2012 Update 2. Any workarounds?

Tags:

Consider the below code:

#include <memory>
#include <future>

using namespace std;

template <typename T, typename Work>
void Test2(future<T> f, Work w)
{
  async([](future<T> && f, Work w)
                      {}, move(f), move(w));
}

int main()
{
  future<int> x = std::async([]()->int{
        std::this_thread::sleep_for(std::chrono::microseconds(200));
        return 10;
    });

  Test2(std::move(x), [](int x){});
    return 0;
}

The above, fails with the following compiler error:

Error 1 error C2664: 'void Test2::::operator ()(std::future<_Ty> &&,Work) const' : cannot convert parameter 1 from 'std::future<_Ty>' to 'std::future<_Ty> &&' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xrefwrap 98 1 ConsoleApplication6

GCC 4.7.2 compiles just fine http://ideone.com/KhMiV6

Before I go ahead and report it on Microsoft Connect:

1) Is this a bug on VC11's part or is this actually standard behavior?

2) Does anyone know of a workaround for this?

EDIT: I have reported it on Microsoft Connect here. For faster resolution, you are encouraged to upvote it.