Returning a reference from a static like shown here is legal C++
static int& from_static() {
static int x;
return x;
}
Everything looks swell so far. But would it also be legal, if the static
variable inside the function was thread_local
instead?
static int& from_thread_local() {
thread_local int x;
return x;
}
Actually, I'm pretty sure it is. But mixing the static
keyword in the declaration of the function with the thread_local
from the variable declaration somehow doesn't sparkle with me.