dynamic initialization of function scoped static __thread variables in clang

375 views Asked by At

I use gcc-4.9 for most of my c++ compilations. Recently I decided on trying the clang for compiling my project. My project make heavy use of gcc's __thread storage.

So, I decided to test this following code

//main.cpp
class A
{
};

int main()
{
    static __thread A * a = new A();
}

when compiled with g++4.9, the code compiles fine (which is expected as gcc supports dynamic initialization of __thread if they are function scoped static.)

but when I compile the same using clang++3.5 I get this error

main.cpp:8:26: error: initializer for thread-local variable must be a constant expression
        static __thread A * a = new A();

So does clang++3.5 missing on this feature ?

I have tried searching for the answer to this(my searching skill is not good), haven't found a satisfactory one, so if I have missed or if this a duplicate question kindly guide me to the original one too.

0

There are 0 answers