int main()
{
thread_local int n;
}
The code above is legal in C++11.
According to cppreference:
The
thread_local
keyword is only allowed for objects declared at namespace scope, objects declared at block scope, and static data members.
I just wonder:
A local variable is always on the current thread's stack, so it's always thread-local. thread_local int n;
is completely identical to int n;
in such contexts.
Why does C++11 allow to declare a local variable as thread_local
, rather than explicitly disable it to avoid abuse?