c++ thread-local storage clang-503.0.40 (Mac OSX)

c++11, clang, macos, thread-local-storage, xcode

Solution

Try `clang++ -stdlib=libc++ -std=c++11`. OS X's outdated libstdc++ doesn't support TLS.

Edit

Ok, this works for the normal clang version but not for the Xcode one.

I did a diff against Apple's clang (503.0.38) and the normal released one and found the following difference:

        .Case("cxx_thread_local",
-                 LangOpts.CPlusPlus11 && PP.getTargetInfo().isTLSSupported() &&
-                 !PP.getTargetInfo().getTriple().isOSDarwin())
+                 LangOpts.CPlusPlus11 && PP.getTargetInfo().isTLSSupported())

So I think this is a bug in Apple's clang version (or they kept it in there on purpose - but still weird, because `-v` says based on 3.4).

Problem

After I declared a variable in this way: ``` #include <thread> namespace thread_space { thread_local int s; } //etc. ``` i tried to compile my code using 'g++ -std=c++0x -pthread [sourcefile]'. I get the following error: ``` example.C:6:8: error: thread-local storage is unsupported for the current target static thread_local int s; ^ 1 error generated. ``` If i try to compile the same code on Linux with GCC 4.8.1 whit the same flags, i get a functioning executable file. I'm using clang-503.0.40 (the one which comes with Xcode 5.1.1) on a MacBook Pro running OSX 10.9.3. Can anybody explain me what i'm doing wrong? Thank you!!

Original source