0

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.)

Hans Olsson
  • 11,123
  • 15
  • 38
  • Quick and dirty: (1) Remove `__attribute((unused))` - (2) Add `(void) zzzz;` somewhere in the code - Related question: https://stackoverflow.com/questions/3417837/what-is-the-best-way-to-suppress-a-unused-variable-x-warning/3418951 – Romain Pereira Nov 30 '22 at 15:14

0 Answers0