Why does this basic thread program fail with Clang but pass in g++?
c++, c++11
Solution
This is a documented bug in clang/libstdc++.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666539
http://llvm.org/bugs/show_bug.cgi?id=12893
From Clang's status page:
Clang's C++11 mode can be used with libc++ or with gcc's libstdc++, but patches are needed to make libstdc++-4.4 work with Clang in C++11 mode. Patches are also needed to make libstdc++-4.6, and libstdc++-4.7 work with Clang releases prior to version 3.2 in C++11 mode.
Problem
I have this simple program that works with threads. In Clang I get a bunch of confusing irrelevant errors. Here is the program: ``` #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(); } ``` Errors: error: no matching constructor for initialization of 'duration' (aka '`std::chrono::duration<long, std::ratio<1, 1000000> >`') : _d(_t.time_since_epoch()) note: in instantiation of function template specialization `'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> > >'` requested here There's a lot more, but you can see it in this link of the program. Oddly, it compiles fine in g++ 4.7.3 and 4.6.3. Why is this only happening in Clang? Update: As David pointed out, it seems only to be failing when I include the `<future>` header.