1 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 150 -o - %s 2 // RUN: %clang_cc1 -verify -fopenmp -std=c++98 -ferror-limit 150 -o - %s 3 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 150 -o - %s 4 5 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 150 -o - %s 6 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 -ferror-limit 150 -o - %s 7 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -ferror-limit 150 -o - %s 8 9 void foo() { 10 } 11 12 bool foobool(int argc) { 13 return argc; 14 } 15 16 void foobar(int &ref) { 17 #pragma omp parallel 18 #pragma omp sections reduction(+:ref) 19 { 20 foo(); 21 } 22 } 23 24 struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}} 25 extern S1 a; 26 class S2 { 27 mutable int a; 28 S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}} 29 30 public: 31 S2() : a(0) {} 32 S2(S2 &s2) : a(s2.a) {} 33 static float S2s; // expected-note 2 {{static data member is predetermined as shared}} 34 static const float S2sc; // expected-note 2 {{'S2sc' declared here}} 35 }; 36 const float S2::S2sc = 0; 37 S2 b; // expected-note 3 {{'b' defined here}} 38 const S2 ba[5]; // expected-note 2 {{'ba' defined here}} 39 class S3 { 40 int a; 41 42 public: 43 int b; 44 S3() : a(0) {} 45 S3(const S3 &s3) : a(s3.a) {} 46 S3 operator+(const S3 &arg1) { return arg1; } 47 }; 48 int operator+(const S3 &arg1, const S3 &arg2) { return 5; } 49 S3 c; // expected-note 3 {{'c' defined here}} 50 const S3 ca[5]; // expected-note 2 {{'ca' defined here}} 51 extern const int f; // expected-note 4 {{'f' declared here}} 52 class S4 { 53 int a; 54 S4(); // expected-note {{implicitly declared private here}} 55 S4(const S4 &s4); 56 S4 &operator+(const S4 &arg) { return (*this); } 57 58 public: 59 S4(int v) : a(v) {} 60 }; 61 S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; } 62 class S5 { 63 int a; 64 S5() : a(0) {} // expected-note {{implicitly declared private here}} 65 S5(const S5 &s5) : a(s5.a) {} 66 S5 &operator+(const S5 &arg); 67 68 public: 69 S5(int v) : a(v) {} 70 }; 71 class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}} 72 #if __cplusplus >= 201103L // C++11 or later 73 // expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}} 74 #endif 75 int a; 76 77 public: 78 S6() : a(6) {} 79 operator int() { return 6; } 80 } o; 81 82 S3 h, k; 83 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} 84 85 template <class T> // expected-note {{declared here}} 86 T tmain(T argc) { 87 const T d = T(); // expected-note 4 {{'d' defined here}} 88 const T da[5] = {T()}; // expected-note 2 {{'da' defined here}} 89 T qa[5] = {T()}; 90 T i; 91 T &j = i; // expected-note 4 {{'j' defined here}} 92 S3 &p = k; // expected-note 2 {{'p' defined here}} 93 const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}} 94 T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}} 95 T fl; 96 #pragma omp parallel 97 #pragma omp sections reduction // expected-error {{expected '(' after 'reduction'}} 98 { 99 foo(); 100 } 101 #pragma omp parallel 102 #pragma omp sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp sections' are ignored}} 103 { 104 foo(); 105 } 106 #pragma omp parallel 107 #pragma omp sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} 108 { 109 foo(); 110 } 111 #pragma omp parallel 112 #pragma omp sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 113 { 114 foo(); 115 } 116 #pragma omp parallel 117 #pragma omp sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 118 { 119 foo(); 120 } 121 #pragma omp parallel 122 #pragma omp sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} 123 { 124 foo(); 125 } 126 #pragma omp parallel 127 #pragma omp sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 128 { 129 foo(); 130 } 131 #pragma omp parallel 132 #pragma omp sections reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} 133 { 134 foo(); 135 } 136 #pragma omp parallel 137 #pragma omp sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} 138 { 139 foo(); 140 } 141 #pragma omp parallel 142 #pragma omp sections reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}} 143 { 144 foo(); 145 } 146 #pragma omp parallel 147 #pragma omp sections reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'float'}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'}} 148 { 149 foo(); 150 } 151 #pragma omp parallel 152 #pragma omp sections reduction(&& : argc) 153 { 154 foo(); 155 } 156 #pragma omp parallel 157 #pragma omp sections reduction(^ : T) // expected-error {{'T' does not refer to a value}} 158 { 159 foo(); 160 } 161 #pragma omp parallel 162 #pragma omp sections reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 3 {{const-qualified list item cannot be reduction}} expected-error 2 {{'operator+' is a private member of 'S2'}} 163 { 164 foo(); 165 } 166 #pragma omp parallel 167 #pragma omp sections reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 4 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified list item cannot be reduction}} 168 { 169 foo(); 170 } 171 #pragma omp parallel 172 #pragma omp sections reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} 173 { 174 foo(); 175 } 176 #pragma omp parallel 177 #pragma omp sections reduction(+ : ba) // expected-error {{const-qualified list item cannot be reduction}} 178 { 179 foo(); 180 } 181 #pragma omp parallel 182 #pragma omp sections reduction(* : ca) // expected-error {{const-qualified list item cannot be reduction}} 183 { 184 foo(); 185 } 186 #pragma omp parallel 187 #pragma omp sections reduction(- : da) // expected-error {{const-qualified list item cannot be reduction}} expected-error {{const-qualified list item cannot be reduction}} 188 { 189 foo(); 190 } 191 #pragma omp parallel 192 #pragma omp sections reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} 193 { 194 foo(); 195 } 196 #pragma omp parallel 197 #pragma omp sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} 198 { 199 foo(); 200 } 201 #pragma omp parallel 202 #pragma omp sections reduction(&& : S2::S2sc) // expected-error {{const-qualified list item cannot be reduction}} 203 { 204 foo(); 205 } 206 #pragma omp parallel 207 #pragma omp sections reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}} 208 { 209 foo(); 210 } 211 #pragma omp parallel 212 #pragma omp sections reduction(+ : o) // expected-error 2 {{no viable overloaded '='}} 213 { 214 foo(); 215 } 216 #pragma omp parallel 217 #pragma omp sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 218 { 219 foo(); 220 } 221 #pragma omp parallel private(k) 222 #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 223 { 224 foo(); 225 } 226 #pragma omp parallel 227 #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}} 228 { 229 foo(); 230 } 231 #pragma omp parallel 232 #pragma omp sections reduction(+ : r) // expected-error 2 {{const-qualified list item cannot be reduction}} 233 { 234 foo(); 235 } 236 #pragma omp parallel shared(i) 237 #pragma omp parallel reduction(min : i) 238 #pragma omp sections reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 239 { 240 foo(); 241 } 242 #pragma omp parallel private(fl) // expected-note 2 {{defined as private}} 243 #pragma omp sections reduction(+ : fl) // expected-error 2 {{reduction variable must be shared}} 244 { 245 foo(); 246 } 247 #pragma omp parallel reduction(* : fl) // expected-note 2 {{defined as reduction}} 248 #pragma omp sections reduction(+ : fl) // expected-error 2 {{reduction variable must be shared}} 249 { 250 foo(); 251 } 252 253 return T(); 254 } 255 256 namespace A { 257 double x; 258 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 259 } 260 namespace B { 261 using A::x; 262 } 263 264 int main(int argc, char **argv) { 265 const int d = 5; // expected-note 2 {{'d' defined here}} 266 const int da[5] = {0}; // expected-note {{'da' defined here}} 267 int qa[5] = {0}; 268 S4 e(4); 269 S5 g(5); 270 int i; 271 int &j = i; // expected-note 2 {{'j' defined here}} 272 S3 &p = k; // expected-note 2 {{'p' defined here}} 273 const int &r = da[i]; // expected-note {{'r' defined here}} 274 int &q = qa[i]; // expected-note {{'q' defined here}} 275 float fl; 276 #pragma omp parallel 277 #pragma omp sections reduction // expected-error {{expected '(' after 'reduction'}} 278 { 279 foo(); 280 } 281 #pragma omp parallel 282 #pragma omp sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp sections' are ignored}} 283 { 284 foo(); 285 } 286 #pragma omp parallel 287 #pragma omp sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} 288 { 289 foo(); 290 } 291 #pragma omp parallel 292 #pragma omp sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 293 { 294 foo(); 295 } 296 #pragma omp parallel 297 #pragma omp sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 298 { 299 foo(); 300 } 301 #pragma omp parallel 302 #pragma omp sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} 303 { 304 foo(); 305 } 306 #pragma omp parallel 307 #pragma omp sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} 308 { 309 foo(); 310 } 311 #pragma omp parallel 312 #pragma omp sections reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}} 313 { 314 foo(); 315 } 316 #pragma omp parallel 317 #pragma omp sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 318 { 319 foo(); 320 } 321 #pragma omp parallel 322 #pragma omp sections reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}} 323 { 324 foo(); 325 } 326 #pragma omp parallel 327 #pragma omp sections reduction(~ : argc) // expected-error {{expected unqualified-id}} 328 { 329 foo(); 330 } 331 #pragma omp parallel 332 #pragma omp sections reduction(&& : argc) 333 { 334 foo(); 335 } 336 #pragma omp parallel 337 #pragma omp sections reduction(^ : S1) // expected-error {{'S1' does not refer to a value}} 338 { 339 foo(); 340 } 341 #pragma omp parallel 342 #pragma omp sections reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{const-qualified list item cannot be reduction}} expected-error {{'operator+' is a private member of 'S2'}} 343 { 344 foo(); 345 } 346 #pragma omp parallel 347 #pragma omp sections reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified list item cannot be reduction}} 348 { 349 foo(); 350 } 351 #pragma omp parallel 352 #pragma omp sections reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} 353 { 354 foo(); 355 } 356 #pragma omp parallel 357 #pragma omp sections reduction(+ : ba) // expected-error {{const-qualified list item cannot be reduction}} 358 { 359 foo(); 360 } 361 #pragma omp parallel 362 #pragma omp sections reduction(* : ca) // expected-error {{const-qualified list item cannot be reduction}} 363 { 364 foo(); 365 } 366 #pragma omp parallel 367 #pragma omp sections reduction(- : da) // expected-error {{const-qualified list item cannot be reduction}} 368 { 369 foo(); 370 } 371 #pragma omp parallel 372 #pragma omp sections reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} 373 { 374 foo(); 375 } 376 #pragma omp parallel 377 #pragma omp sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} 378 { 379 foo(); 380 } 381 #pragma omp parallel 382 #pragma omp sections reduction(&& : S2::S2sc) // expected-error {{const-qualified list item cannot be reduction}} 383 { 384 foo(); 385 } 386 #pragma omp parallel 387 #pragma omp sections reduction(& : e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{invalid operands to binary expression ('S4' and 'S4')}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}} 388 { 389 foo(); 390 } 391 #pragma omp parallel 392 #pragma omp sections reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}} 393 { 394 foo(); 395 } 396 #pragma omp parallel 397 #pragma omp sections reduction(+ : o) // expected-error {{no viable overloaded '='}} 398 { 399 foo(); 400 } 401 #pragma omp parallel 402 #pragma omp sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 403 { 404 foo(); 405 } 406 #pragma omp parallel private(k) 407 #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 408 { 409 foo(); 410 } 411 #pragma omp parallel 412 #pragma omp sections reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}} 413 { 414 foo(); 415 } 416 #pragma omp parallel 417 #pragma omp sections reduction(+ : r) // expected-error {{const-qualified list item cannot be reduction}} 418 { 419 foo(); 420 } 421 #pragma omp parallel shared(i) 422 #pragma omp parallel reduction(min : i) 423 #pragma omp sections reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} 424 { 425 foo(); 426 } 427 #pragma omp parallel private(fl) // expected-note {{defined as private}} 428 #pragma omp sections reduction(+ : fl) // expected-error {{reduction variable must be shared}} 429 { 430 foo(); 431 } 432 #pragma omp parallel reduction(* : fl) // expected-note {{defined as reduction}} 433 #pragma omp sections reduction(+ : fl) // expected-error {{reduction variable must be shared}} 434 { 435 foo(); 436 } 437 static int m; 438 #pragma omp sections reduction(+ : m) // OK 439 { 440 foo(); 441 } 442 443 return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}} 444 } 445