Why does this thread base program fail with Clang but pass in g ++?

I have this simple program that works with threads. In Clang, I get a bunch of confusing 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 correspondence constructor to initialize 'duration' (aka ' std::chrono::duration<long, std::ratio<1, 1000000> > '): _d (_t.time_since_epoch ()) note: when requested, it is requested here function template specification '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> > >' here

There is a lot more, but you can see it in this program link . Oddly enough, it compiles in g ++ 4.7.3 and 4.6.3. Why is this happening only in Clang?

Update:. As David remarked, this seems like a mistake when I include the <future> header.

+7
source share
3 answers

This is a documented error in clang / libstdc ++.

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

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

From the Clang status page :

Clang C ++ 11 mode can be used with lib ++ or with gcc libstd ++, but corrections are needed to create libstd ++ - 4.4 working with Clang in C ++ 11 mode. Patches are also needed to create libstdC ++ - 4.6, and libstdC ++ - 4.7 work with Clang releases up to version 3.2 in C ++ 11 mode.

+6
source

This is an incompatibility between libstdc ++ and clang. If you want to build against libstdc ++ 4.8.0, this problem will disappear.

 [11:43am][ wlynch@apple /tmp] /opt/llvm/3.2/bin/clang++ -std=gnu++11 -gcc-toolchain /opt/gcc/4.8.0 se.cc |& wc -l 0 [11:43am][ wlynch@apple /tmp] /opt/llvm/3.2/bin/clang++ -std=gnu++11 -gcc-toolchain /opt/gcc/4.7.2 se.cc |& wc -l 21 
+1
source

If this happens with clang 3.2, this is not bug 12893 (which was fixed in clang 3.2).

Most likely there will be this error , which is actually an error in libstdc ++ 4.7: <a2>

+1
source

All Articles