Bug 34303 - C++ class variable gets compiler error "declared 'threadprivate' after first use"
Summary: C++ class variable gets compiler error "declared 'threadprivate' after first ...
Status: RESOLVED DUPLICATE of bug 27557
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-30 19:11 UTC by Geir Johansen
Modified: 2007-11-30 21:56 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geir Johansen 2007-11-30 19:11:39 UTC
+++ 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
$
Comment 1 Andrew Pinski 2007-11-30 21:56:33 UTC
>This bug presented here is likely the same as Bug #27557, but this test case
>does not involve a non-POD type.

T is a non POD type.  It has a non trivial copy constructor and/or constructor.

*** This bug has been marked as a duplicate of 27557 ***