+++ This bug was initially created as a clone of Bug #27557 +++

This bug presented here is likely the same as Bug #27557, but this test case
does not involve a non-POD type.

Following program gets a compile time error with g++, but is able to compile
and execute using PGI and PathScale compilers.  


$ cat bug2907.cpp
/*  derived from OpenMP API Ver 2.5 p. 159 Example A.22.3c  */
#include <omp.h>
#include <stdio.h>
#define NT 4

class T {
 public:
  int val;
  T (int);
  T (const T&);
};
T :: T (int v){
  val = v;
}
T :: T (const T& t) {
  val = t.val;
}

int x = 1;
const T b_aux(x);
T b(b_aux);

#pragma omp threadprivate(b)

int main()
{
  int save_val;
  omp_set_num_threads(NT);
  x++;

#pragma omp parallel default(none) shared(save_val)
  {
    if (omp_get_thread_num()==0)  save_val = b.val;
  }

  printf("save_val=%d\n",save_val);
  return 0;
}

$ g++ -fopenmp bug2907.cpp
bug2907.cpp:23: error: 'b' declared 'threadprivate' after first use
bug2907.cpp: In function 'int main()':
bug2907.cpp:33: error: 'b' not specified in enclosing parallel
bug2907.cpp:31: error: enclosing parallel
$ pathCC -mp bug2907.cpp; ./a.out
save_val=1
$ pgCC -mp=nonuma bug2907.cpp; ./a.out
Warning: omp_set_num_threads (4) greater than available cpus (1)
save_val=1
$


-- 
           Summary: C++ class variable gets compiler error "declared
                    'threadprivate' after first use"
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: geir at cray dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34303

Reply via email to