GNU Does Not Distinguish Between __thread and thread_local
Error Information
1 2 3 4 5 6 | error: thread-local declaration of 'test' with static initialization follows declaration with dynamic initialization 3 | __thread long test; | ^ note: previous declaration is here 1 | extern thread_local long test; | ^ |
Problem
The __thread identifier is different from the thread_local identifier. The __thread identifier is for static initialization, and the thread_local identifier is for dynamic initialization. Therefore, they cannot be specified at the same time. GNU uses the following processing logic:
Source Code |
Processing Logic |
|---|---|
extern __thread a; extern thread_local a; |
The later identifier prevails. |
__thread a; extern thread_local; |
Regardless of the sequence, __thread prevails. |
extern __thread a; thread_local a; |
Regardless of the sequence, __thread prevails. |
For non-extern thread_local, GNU processes it as __thread. |
|
Solution
- Modify the statement based on the actual code requirements.
- Use the clang-tidy tool to identify such issues and provide modification suggestions.
Parent topic: Other Compatibility Problems