Consider the following fragment compiled with gcc /openmp /Wall:
static __attribute((unused)) int zzzz;
#pragma omp threadprivate(zzzz)
It gives this error message
error: ‘zzzz’ declared ‘threadprivate’ after first use
Just removing the attribute gives:
warning: ‘zzzz’ defined but not used [-Wunused-variable]
To me that looks like a clear compiler-defect, as if "unused" sets "used-flag" and then threadprivate trips on that.
The error message is the same as in openMP C++ error with threadprivate vector - so I suppose it has a similar underlying cause, however, this is C-code not C++ and thread_local as storage class seems C++-specific.
Are there any good work-arounds for this? (I know the obvious solution of removing or using the variable.)