为什么这个基本的线程程序与Clang失败但传入g ++?

tem*_*boy 7 c++ c++11

我有这个简单的程序,适用于线程.在Clang我得到了一堆令人困惑的无关错误.这是程序:

#include <iostream>
#include <thread>
#include <future>

int main()
{
   std::packaged_task<int()> task([] { return 1; });
   std::future<int> result = task.get_future();

   task();

   std::cout << "Result was: " << result.get();
}
Run Code Online (Sandbox Code Playgroud)

错误:

错误:没有用于初始化'duration'的匹配构造函数(又名' std::chrono::duration<long, std::ratio<1, 1000000> >'):_ d( _t.time_since_epoch())注意:在'std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<long, std::ratio<1, 1000000> > >::time_point<std::chrono::duration<long, std::ratio<1, 1000000000> > >'此处请求的函数模板特化的实例化

还有更多,但你可以在程序的这个链接中看到它.奇怪的是,它在g ++ 4.7.3和4.6.3中编译得很好.为什么这只发生在Clang?

更新:正如大卫指出的那样,当我包含<future>标题时,似乎只会失败.

Dre*_*ann 6

这是clang/libstdc ++中记录的错误.

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666539

http://llvm.org/bugs/show_bug.cgi?id=12893

来自Clang的状态页面:

Clang的C++ 11模式可以与libc ++或gcc的libstdc ++一起使用,但需要使用补丁来使libstdc ++ - 4.4在C++ 11模式下与Clang一起使用.还需要补丁来制作libstdc ++ - 4.6,并且libstdc ++ - 4.7与C++ 11模式版本3.2之前的Clang版本一起使用.

  • 实际上包括`<chrono>`对我有用. (2认同)