1 // RUN: %clang_cc1 -verify -fopenmp %s 2 3 void foo() { 4 } 5 6 bool foobool(int argc) { 7 return argc; 8 } 9 10 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} 11 extern S1 a; 12 class S2 { 13 mutable int a; 14 15 public: 16 S2() : a(0) {} 17 }; 18 const S2 b; 19 const S2 ba[5]; 20 class S3 { 21 int a; 22 23 public: 24 S3() : a(0) {} 25 }; 26 const S3 ca[5]; 27 class S4 { 28 int a; 29 S4(); // expected-note {{implicitly declared private here}} 30 31 public: 32 S4(int v) : a(v) {} 33 }; 34 class S5 { 35 int a; 36 S5() : a(0) {} // expected-note {{implicitly declared private here}} 37 38 public: 39 S5(int v) : a(v) {} 40 }; 41 42 S3 h; 43 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 44 45 template <class I, class C> 46 int foomain(I argc, C **argv) { 47 I e(4); 48 I g(5); 49 int i; 50 int &j = i; 51 #pragma omp for private // expected-error {{expected '(' after 'private'}} 52 for (int k = 0; k < argc; ++k) 53 ++k; 54 #pragma omp for private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 55 for (int k = 0; k < argc; ++k) 56 ++k; 57 #pragma omp for private() // expected-error {{expected expression}} 58 for (int k = 0; k < argc; ++k) 59 ++k; 60 #pragma omp for private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 61 for (int k = 0; k < argc; ++k) 62 ++k; 63 #pragma omp for private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 64 for (int k = 0; k < argc; ++k) 65 ++k; 66 #pragma omp for private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 67 for (int k = 0; k < argc; ++k) 68 ++k; 69 #pragma omp for private(argc) 70 for (int k = 0; k < argc; ++k) 71 ++k; 72 #pragma omp for private(S1) // expected-error {{'S1' does not refer to a value}} 73 for (int k = 0; k < argc; ++k) 74 ++k; 75 #pragma omp for private(a, b) // expected-error {{private variable with incomplete type 'S1'}} 76 for (int k = 0; k < argc; ++k) 77 ++k; 78 #pragma omp for private(argv[1]) // expected-error {{expected variable name}} 79 for (int k = 0; k < argc; ++k) 80 ++k; 81 #pragma omp for private(e, g) 82 for (int k = 0; k < argc; ++k) 83 ++k; 84 #pragma omp for private(h) // expected-error {{threadprivate or thread local variable cannot be private}} 85 for (int k = 0; k < argc; ++k) 86 ++k; 87 #pragma omp for shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp for'}} 88 for (int k = 0; k < argc; ++k) 89 ++k; 90 #pragma omp parallel 91 { 92 int v = 0; 93 int i; 94 #pragma omp for private(i) 95 for (int k = 0; k < argc; ++k) { 96 i = k; 97 v += i; 98 } 99 } 100 #pragma omp parallel shared(i) 101 #pragma omp parallel private(i) 102 #pragma omp for private(j) 103 for (int k = 0; k < argc; ++k) 104 ++k; 105 #pragma omp for private(i) 106 for (int k = 0; k < argc; ++k) 107 ++k; 108 return 0; 109 } 110 111 void bar(S4 a[2]) { 112 #pragma omp parallel 113 #pragma omp for private(a) 114 for (int i = 0; i < 2; ++i) 115 foo(); 116 } 117 118 namespace A { 119 double x; 120 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 121 } 122 namespace B { 123 using A::x; 124 } 125 126 int main(int argc, char **argv) { 127 S4 e(4); 128 S5 g(5); 129 int i; 130 int &j = i; 131 #pragma omp for private // expected-error {{expected '(' after 'private'}} 132 for (int k = 0; k < argc; ++k) 133 ++k; 134 #pragma omp for private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 135 for (int k = 0; k < argc; ++k) 136 ++k; 137 #pragma omp for private() // expected-error {{expected expression}} 138 for (int k = 0; k < argc; ++k) 139 ++k; 140 #pragma omp for private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 141 for (int k = 0; k < argc; ++k) 142 ++k; 143 #pragma omp for private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 144 for (int k = 0; k < argc; ++k) 145 ++k; 146 #pragma omp for private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 147 for (int k = 0; k < argc; ++k) 148 ++k; 149 #pragma omp for private(argc) 150 for (int k = 0; k < argc; ++k) 151 ++k; 152 #pragma omp for private(S1) // expected-error {{'S1' does not refer to a value}} 153 for (int k = 0; k < argc; ++k) 154 ++k; 155 #pragma omp for private(a, b) // expected-error {{private variable with incomplete type 'S1'}} 156 for (int k = 0; k < argc; ++k) 157 ++k; 158 #pragma omp for private(argv[1]) // expected-error {{expected variable name}} 159 for (int k = 0; k < argc; ++k) 160 ++k; 161 #pragma omp for private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 162 for (int k = 0; k < argc; ++k) 163 ++k; 164 #pragma omp for private(h) // expected-error {{threadprivate or thread local variable cannot be private}} 165 for (int k = 0; k < argc; ++k) 166 ++k; 167 #pragma omp for private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}} 168 for (int k = 0; k < argc; ++k) 169 ++k; 170 #pragma omp for shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp for'}} 171 for (int k = 0; k < argc; ++k) 172 ++k; 173 #pragma omp parallel 174 { 175 int i; 176 #pragma omp for private(i) 177 for (int k = 0; k < argc; ++k) 178 ++k; 179 } 180 #pragma omp parallel shared(i) 181 #pragma omp parallel private(i) 182 #pragma omp for private(j) 183 for (int k = 0; k < argc; ++k) 184 ++k; 185 #pragma omp for private(i) 186 for (int k = 0; k < argc; ++k) 187 ++k; 188 static int si; 189 #pragma omp for private(si) // OK 190 for(int k = 0; k < argc; ++k) 191 si = k + 1; 192 193 return 0; 194 } 195 196