Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s
      2 
      3 void foo() {
      4 }
      5 
      6 bool foobool(int argc) {
      7   return argc;
      8 }
      9 
     10 struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
     11 extern S1 a;
     12 class S2 {
     13   mutable int a;
     14 
     15 public:
     16   S2() : a(0) {}
     17   static float S2s; // expected-note {{static data member is predetermined as shared}}
     18 };
     19 const S2 b;
     20 const S2 ba[5];
     21 class S3 {
     22   int a;
     23 
     24 public:
     25   S3() : a(0) {}
     26 };
     27 const S3 c;         // expected-note {{global variable is predetermined as shared}}
     28 const S3 ca[5];     // expected-note {{global variable is predetermined as shared}}
     29 extern const int f; // expected-note {{global variable is predetermined as shared}}
     30 class S4 {
     31   int a;
     32   S4(); // expected-note {{implicitly declared private here}}
     33 
     34 public:
     35   S4(int v) : a(v) {}
     36 };
     37 class S5 {
     38   int a;
     39   S5() : a(0) {} // expected-note {{implicitly declared private here}}
     40 
     41 public:
     42   S5(int v) : a(v) {}
     43 };
     44 
     45 int threadvar;
     46 #pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}}
     47 
     48 void bar(int n, int b[n]) {
     49 #pragma omp task private(b)
     50     foo();
     51 }
     52 
     53 namespace A {
     54 double x;
     55 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
     56 }
     57 namespace B {
     58 using A::x;
     59 }
     60 
     61 int main(int argc, char **argv) {
     62   const int d = 5;       // expected-note {{constant variable is predetermined as shared}}
     63   const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
     64   S4 e(4);
     65   S5 g(5);
     66   int i;
     67   int &j = i;
     68 #pragma omp task private                               // expected-error {{expected '(' after 'private'}}
     69 #pragma omp task private(                              // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     70 #pragma omp task private()                             // expected-error {{expected expression}}
     71 #pragma omp task private(argc                          // expected-error {{expected ')'}} expected-note {{to match this '('}}
     72 #pragma omp task private(argc,                         // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
     73 #pragma omp task private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
     74 #pragma omp task private(argc argv)                    // expected-error {{expected ',' or ')' in 'private' clause}}
     75 #pragma omp task private(S1)                           // expected-error {{'S1' does not refer to a value}}
     76 #pragma omp task private(a, b, c, d, f)                // expected-error {{a private variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be private}}
     77 #pragma omp task private(argv[1])                      // expected-error {{expected variable name}}
     78 #pragma omp task private(ba)
     79 #pragma omp task private(ca)           // expected-error {{shared variable cannot be private}}
     80 #pragma omp task private(da)           // expected-error {{shared variable cannot be private}}
     81 #pragma omp task private(S2::S2s)      // expected-error {{shared variable cannot be private}}
     82 #pragma omp task private(e, g)         // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
     83 #pragma omp task private(threadvar, B::x)    // expected-error 2 {{threadprivate or thread local variable cannot be private}}
     84 #pragma omp task shared(i), private(i) // expected-error {{shared variable cannot be private}} expected-note {{defined as shared}}
     85   foo();
     86 #pragma omp task firstprivate(i) private(i) // expected-error {{firstprivate variable cannot be private}} expected-note {{defined as firstprivate}}
     87   foo();
     88 #pragma omp task private(i)
     89 #pragma omp task private(j)
     90   foo();
     91 #pragma omp task firstprivate(i)
     92   for (int k = 0; k < 10; ++k) {
     93 #pragma omp task private(i)
     94     foo();
     95   }
     96   static int m;
     97 #pragma omp task private(m) // OK
     98     foo();
     99 
    100   return 0;
    101 }
    102