-
Notifications
You must be signed in to change notification settings - Fork 16.8k
C23 mode doesn't compile thread local declarations properly #69167
Description
In C23, the keywords _Thread_local and thread_local are synonyms. But with clang 17 the following code does not compile
extern thread_local unsigned a;
_Thread_local unsigned a = 0;This is because clang seems to use different tls models for the two declarations. (gcc has no problem and uses static initialization for both.)
Obviously nobody would write such code with two different specifications consciously, but I stumbled into this because I had extern declaration and definition in different files, both using thread_local. One of them included threads.h and the other one didn't. So one got replaced by the C17 macro definition in that header to _Thread_local.
Generally I think that dynamic initialization for thread local storage should not be used in C mode, in particular not in C23 mode. C never needs dynamic initialization.