1// RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s 2 3class S { 4 int a; 5 S() : a(0) {} 6 7public: 8 S(int v) : a(v) {} 9 S(const S &s) : a(s.a) {} 10}; 11 12static int sii; 13#pragma omp threadprivate(sii) // expected-note {{defined as threadprivate or thread local}} 14static int globalii; 15 16int test_iteration_spaces() { 17 const int N = 100; 18 float a[N], b[N], c[N]; 19 int ii, jj, kk; 20 float fii; 21 double dii; 22#pragma omp parallel for 23 for (int i = 0; i < 10; i += 1) { 24 c[i] = a[i] + b[i]; 25 } 26#pragma omp parallel for 27 for (char i = 0; i < 10; i++) { 28 c[i] = a[i] + b[i]; 29 } 30#pragma omp parallel for 31 for (char i = 0; i < 10; i += '\1') { 32 c[i] = a[i] + b[i]; 33 } 34#pragma omp parallel for 35 for (long long i = 0; i < 10; i++) { 36 c[i] = a[i] + b[i]; 37 } 38// expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}} 39#pragma omp parallel for 40 for (long long i = 0; i < 10; i += 1.5) { 41 c[i] = a[i] + b[i]; 42 } 43#pragma omp parallel for 44 for (long long i = 0; i < 'z'; i += 1u) { 45 c[i] = a[i] + b[i]; 46 } 47// expected-error@+2 {{variable must be of integer or random access iterator type}} 48#pragma omp parallel for 49 for (float fi = 0; fi < 10.0; fi++) { 50 c[(int)fi] = a[(int)fi] + b[(int)fi]; 51 } 52// expected-error@+2 {{variable must be of integer or random access iterator type}} 53#pragma omp parallel for 54 for (double fi = 0; fi < 10.0; fi++) { 55 c[(int)fi] = a[(int)fi] + b[(int)fi]; 56 } 57// expected-error@+2 {{variable must be of integer or random access iterator type}} 58#pragma omp parallel for 59 for (int &ref = ii; ref < 10; ref++) { 60 } 61// expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} 62#pragma omp parallel for 63 for (int i; i < 10; i++) 64 c[i] = a[i]; 65 66// expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} 67#pragma omp parallel for 68 for (int i = 0, j = 0; i < 10; ++i) 69 c[i] = a[i]; 70 71// expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} 72#pragma omp parallel for 73 for (; ii < 10; ++ii) 74 c[ii] = a[ii]; 75 76// expected-warning@+3 {{expression result unused}} 77// expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} 78#pragma omp parallel for 79 for (ii + 1; ii < 10; ++ii) 80 c[ii] = a[ii]; 81 82// expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} 83#pragma omp parallel for 84 for (c[ii] = 0; ii < 10; ++ii) 85 c[ii] = a[ii]; 86 87// Ok to skip parenthesises. 88#pragma omp parallel for 89 for (((ii)) = 0; ii < 10; ++ii) 90 c[ii] = a[ii]; 91 92// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 93#pragma omp parallel for 94 for (int i = 0; i; i++) 95 c[i] = a[i]; 96 97// expected-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 98// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}} 99#pragma omp parallel for 100 for (int i = 0; jj < kk; ii++) 101 c[i] = a[i]; 102 103// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 104#pragma omp parallel for 105 for (int i = 0; !!i; i++) 106 c[i] = a[i]; 107 108// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 109#pragma omp parallel for 110 for (int i = 0; i != 1; i++) 111 c[i] = a[i]; 112 113// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} 114#pragma omp parallel for 115 for (int i = 0;; i++) 116 c[i] = a[i]; 117 118// Ok. 119#pragma omp parallel for 120 for (int i = 11; i > 10; i--) 121 c[i] = a[i]; 122 123// Ok. 124#pragma omp parallel for 125 for (int i = 0; i < 10; ++i) 126 c[i] = a[i]; 127 128// Ok. 129#pragma omp parallel for 130 for (ii = 0; ii < 10; ++ii) 131 c[ii] = a[ii]; 132 133// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 134#pragma omp parallel for 135 for (ii = 0; ii < 10; ++jj) 136 c[ii] = a[jj]; 137 138// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 139#pragma omp parallel for 140 for (ii = 0; ii < 10; ++++ii) 141 c[ii] = a[ii]; 142 143// Ok but undefined behavior (in general, cannot check that incr 144// is really loop-invariant). 145#pragma omp parallel for 146 for (ii = 0; ii < 10; ii = ii + ii) 147 c[ii] = a[ii]; 148 149// expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}} 150#pragma omp parallel for 151 for (ii = 0; ii < 10; ii = ii + 1.0f) 152 c[ii] = a[ii]; 153 154// Ok - step was converted to integer type. 155#pragma omp parallel for 156 for (ii = 0; ii < 10; ii = ii + (int)1.1f) 157 c[ii] = a[ii]; 158 159// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 160#pragma omp parallel for 161 for (ii = 0; ii < 10; jj = ii + 2) 162 c[ii] = a[ii]; 163 164// expected-warning@+3 {{relational comparison result unused}} 165// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 166#pragma omp parallel for 167 for (ii = 0; ii<10; jj> kk + 2) 168 c[ii] = a[ii]; 169 170// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 171#pragma omp parallel for 172 for (ii = 0; ii < 10;) 173 c[ii] = a[ii]; 174 175// expected-warning@+3 {{expression result unused}} 176// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 177#pragma omp parallel for 178 for (ii = 0; ii < 10; !ii) 179 c[ii] = a[ii]; 180 181// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 182#pragma omp parallel for 183 for (ii = 0; ii < 10; ii ? ++ii : ++jj) 184 c[ii] = a[ii]; 185 186// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} 187#pragma omp parallel for 188 for (ii = 0; ii < 10; ii = ii < 10) 189 c[ii] = a[ii]; 190 191// expected-note@+3 {{loop step is expected to be positive due to this condition}} 192// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 193#pragma omp parallel for 194 for (ii = 0; ii < 10; ii = ii + 0) 195 c[ii] = a[ii]; 196 197// expected-note@+3 {{loop step is expected to be positive due to this condition}} 198// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 199#pragma omp parallel for 200 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45)) 201 c[ii] = a[ii]; 202 203// expected-note@+3 {{loop step is expected to be positive due to this condition}} 204// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 205#pragma omp parallel for 206 for (ii = 0; (ii) < 10; ii -= 25) 207 c[ii] = a[ii]; 208 209// expected-note@+3 {{loop step is expected to be positive due to this condition}} 210// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 211#pragma omp parallel for 212 for (ii = 0; (ii < 10); ii -= 0) 213 c[ii] = a[ii]; 214 215// expected-note@+3 {{loop step is expected to be negative due to this condition}} 216// expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} 217#pragma omp parallel for 218 for (ii = 0; ii > 10; (ii += 0)) 219 c[ii] = a[ii]; 220 221// expected-note@+3 {{loop step is expected to be positive due to this condition}} 222// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 223#pragma omp parallel for 224 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii)) 225 c[ii] = a[ii]; 226 227// expected-note@+3 {{loop step is expected to be negative due to this condition}} 228// expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} 229#pragma omp parallel for 230 for ((ii = 0); ii > 10; (ii -= 0)) 231 c[ii] = a[ii]; 232 233// expected-note@+3 {{loop step is expected to be positive due to this condition}} 234// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} 235#pragma omp parallel for 236 for (ii = 0; (ii < 10); (ii -= 0)) 237 c[ii] = a[ii]; 238 239// expected-note@+2 {{defined as firstprivate}} 240// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be firstprivate, predetermined as private}} 241#pragma omp parallel for firstprivate(ii) 242 for (ii = 0; ii < 10; ii++) 243 c[ii] = a[ii]; 244 245// expected-error@+3 {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel for'}} 246// expected-note@+2 {{defined as linear}} 247// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be linear, predetermined as private}} 248#pragma omp parallel for linear(ii) 249 for (ii = 0; ii < 10; ii++) 250 c[ii] = a[ii]; 251 252#pragma omp parallel for private(ii) 253 for (ii = 0; ii < 10; ii++) 254 c[ii] = a[ii]; 255 256#pragma omp parallel for lastprivate(ii) 257 for (ii = 0; ii < 10; ii++) 258 c[ii] = a[ii]; 259 260 { 261// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be threadprivate or thread local, predetermined as private}} 262#pragma omp parallel for 263 for (sii = 0; sii < 10; sii += 1) 264 c[sii] = a[sii]; 265 } 266 267 { 268// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be a variable with global storage without being explicitly marked as private}} 269#pragma omp parallel for 270 for (globalii = 0; globalii < 10; globalii += 1) 271 c[globalii] = a[globalii]; 272 } 273 274 { 275// expected-error@+3 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be a variable with global storage without being explicitly marked as private}} 276#pragma omp parallel for collapse(2) 277 for (ii = 0; ii < 10; ii += 1) 278 for (globalii = 0; globalii < 10; globalii += 1) 279 c[globalii] += a[globalii] + ii; 280 } 281 282// expected-error@+2 {{statement after '#pragma omp parallel for' must be a for loop}} 283#pragma omp parallel for 284 for (auto &item : a) { 285 item = item + 1; 286 } 287 288// expected-note@+3 {{loop step is expected to be positive due to this condition}} 289// expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}} 290#pragma omp parallel for 291 for (unsigned i = 9; i < 10; i--) { 292 c[i] = a[i] + b[i]; 293 } 294 295 int(*lb)[4] = nullptr; 296#pragma omp parallel for 297 for (int(*p)[4] = lb; p < lb + 8; ++p) { 298 } 299 300// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 301#pragma omp parallel for 302 for (int a{0}; a < 10; ++a) { 303 } 304 305 return 0; 306} 307 308// Iterators allowed in openmp for-loops. 309namespace std { 310struct random_access_iterator_tag {}; 311template <class Iter> 312struct iterator_traits { 313 typedef typename Iter::difference_type difference_type; 314 typedef typename Iter::iterator_category iterator_category; 315}; 316template <class Iter> 317typename iterator_traits<Iter>::difference_type 318distance(Iter first, Iter last) { return first - last; } 319} 320class Iter0 { 321public: 322 Iter0() {} 323 Iter0(const Iter0 &) {} 324 Iter0 operator++() { return *this; } 325 Iter0 operator--() { return *this; } 326 bool operator<(Iter0 a) { return true; } 327}; 328// expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}} 329// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}} 330int operator-(Iter0 a, Iter0 b) { return 0; } 331class Iter1 { 332public: 333 Iter1(float f = 0.0f, double d = 0.0) {} 334 Iter1(const Iter1 &) {} 335 Iter1 operator++() { return *this; } 336 Iter1 operator--() { return *this; } 337 bool operator<(Iter1 a) { return true; } 338 bool operator>=(Iter1 a) { return false; } 339}; 340class GoodIter { 341public: 342 GoodIter() {} 343 GoodIter(const GoodIter &) {} 344 GoodIter(int fst, int snd) {} 345 GoodIter &operator=(const GoodIter &that) { return *this; } 346 GoodIter &operator=(const Iter0 &that) { return *this; } 347 GoodIter &operator+=(int x) { return *this; } 348 GoodIter &operator-=(int x) { return *this; } 349 explicit GoodIter(void *) {} 350 GoodIter operator++() { return *this; } 351 GoodIter operator--() { return *this; } 352 bool operator!() { return true; } 353 bool operator<(GoodIter a) { return true; } 354 bool operator<=(GoodIter a) { return true; } 355 bool operator>=(GoodIter a) { return false; } 356 typedef int difference_type; 357 typedef std::random_access_iterator_tag iterator_category; 358}; 359// expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}} 360// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} 361int operator-(GoodIter a, GoodIter b) { return 0; } 362// expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}} 363GoodIter operator-(GoodIter a) { return a; } 364// expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}} 365// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} 366GoodIter operator-(GoodIter a, int v) { return GoodIter(); } 367// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}} 368GoodIter operator+(GoodIter a, int v) { return GoodIter(); } 369// expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}} 370// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}} 371GoodIter operator-(int v, GoodIter a) { return GoodIter(); } 372// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}} 373GoodIter operator+(int v, GoodIter a) { return GoodIter(); } 374 375int test_with_random_access_iterator() { 376 GoodIter begin, end; 377 Iter0 begin0, end0; 378#pragma omp parallel for 379 for (GoodIter I = begin; I < end; ++I) 380 ++I; 381// expected-error@+2 {{variable must be of integer or random access iterator type}} 382#pragma omp parallel for 383 for (GoodIter &I = begin; I < end; ++I) 384 ++I; 385#pragma omp parallel for 386 for (GoodIter I = begin; I >= end; --I) 387 ++I; 388// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 389#pragma omp parallel for 390 for (GoodIter I(begin); I < end; ++I) 391 ++I; 392// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 393#pragma omp parallel for 394 for (GoodIter I(nullptr); I < end; ++I) 395 ++I; 396// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 397#pragma omp parallel for 398 for (GoodIter I(0); I < end; ++I) 399 ++I; 400// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 401#pragma omp parallel for 402 for (GoodIter I(1, 2); I < end; ++I) 403 ++I; 404#pragma omp parallel for 405 for (begin = GoodIter(0); begin < end; ++begin) 406 ++begin; 407// expected-error@+3 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}} 408// expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} 409#pragma omp parallel for 410 for (begin = begin0; begin < end; ++begin) 411 ++begin; 412// expected-error@+2 {{initialization clause of OpenMP for loop must be of the form 'var = init' or 'T var = init'}} 413#pragma omp parallel for 414 for (++begin; begin < end; ++begin) 415 ++begin; 416#pragma omp parallel for 417 for (begin = end; begin < end; ++begin) 418 ++begin; 419// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} 420#pragma omp parallel for 421 for (GoodIter I = begin; I - I; ++I) 422 ++I; 423// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} 424#pragma omp parallel for 425 for (GoodIter I = begin; begin < end; ++I) 426 ++I; 427// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} 428#pragma omp parallel for 429 for (GoodIter I = begin; !I; ++I) 430 ++I; 431// expected-note@+3 {{loop step is expected to be negative due to this condition}} 432// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 433#pragma omp parallel for 434 for (GoodIter I = begin; I >= end; I = I + 1) 435 ++I; 436#pragma omp parallel for 437 for (GoodIter I = begin; I >= end; I = I - 1) 438 ++I; 439// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} 440#pragma omp parallel for 441 for (GoodIter I = begin; I >= end; I = -I) 442 ++I; 443// expected-note@+3 {{loop step is expected to be negative due to this condition}} 444// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 445#pragma omp parallel for 446 for (GoodIter I = begin; I >= end; I = 2 + I) 447 ++I; 448// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} 449#pragma omp parallel for 450 for (GoodIter I = begin; I >= end; I = 2 - I) 451 ++I; 452// expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}} 453#pragma omp parallel for 454 for (Iter0 I = begin0; I < end0; ++I) 455 ++I; 456// Initializer is constructor without params. 457// expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}} 458// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 459#pragma omp parallel for 460 for (Iter0 I; I < end0; ++I) 461 ++I; 462 Iter1 begin1, end1; 463// expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} 464// expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} 465#pragma omp parallel for 466 for (Iter1 I = begin1; I < end1; ++I) 467 ++I; 468// expected-note@+3 {{loop step is expected to be negative due to this condition}} 469// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 470#pragma omp parallel for 471 for (Iter1 I = begin1; I >= end1; ++I) 472 ++I; 473// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} 474// expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} 475// Initializer is constructor with all default params. 476// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} 477#pragma omp parallel for 478 for (Iter1 I; I < end1; ++I) { 479 } 480 return 0; 481} 482 483template <typename IT, int ST> 484class TC { 485public: 486 int dotest_lt(IT begin, IT end) { 487// expected-note@+3 {{loop step is expected to be positive due to this condition}} 488// expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} 489#pragma omp parallel for 490 for (IT I = begin; I < end; I = I + ST) { 491 ++I; 492 } 493// expected-note@+3 {{loop step is expected to be positive due to this condition}} 494// expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} 495#pragma omp parallel for 496 for (IT I = begin; I <= end; I += ST) { 497 ++I; 498 } 499#pragma omp parallel for 500 for (IT I = begin; I < end; ++I) { 501 ++I; 502 } 503 } 504 505 static IT step() { 506 return IT(ST); 507 } 508}; 509template <typename IT, int ST = 0> 510int dotest_gt(IT begin, IT end) { 511// expected-note@+3 2 {{loop step is expected to be negative due to this condition}} 512// expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 513#pragma omp parallel for 514 for (IT I = begin; I >= end; I = I + ST) { 515 ++I; 516 } 517// expected-note@+3 2 {{loop step is expected to be negative due to this condition}} 518// expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 519#pragma omp parallel for 520 for (IT I = begin; I >= end; I += ST) { 521 ++I; 522 } 523 524// expected-note@+3 {{loop step is expected to be negative due to this condition}} 525// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} 526#pragma omp parallel for 527 for (IT I = begin; I >= end; ++I) { 528 ++I; 529 } 530 531#pragma omp parallel for 532 for (IT I = begin; I < end; I += TC<int, ST>::step()) { 533 ++I; 534 } 535} 536 537void test_with_template() { 538 GoodIter begin, end; 539 TC<GoodIter, 100> t1; 540 TC<GoodIter, -100> t2; 541 t1.dotest_lt(begin, end); 542 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}} 543 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}} 544 dotest_gt<unsigned, -10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, -10>' requested here}} 545} 546 547void test_loop_break() { 548 const int N = 100; 549 float a[N], b[N], c[N]; 550#pragma omp parallel for 551 for (int i = 0; i < 10; i++) { 552 c[i] = a[i] + b[i]; 553 for (int j = 0; j < 10; ++j) { 554 if (a[i] > b[j]) 555 break; // OK in nested loop 556 } 557 switch (i) { 558 case 1: 559 b[i]++; 560 break; 561 default: 562 break; 563 } 564 if (c[i] > 10) 565 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} 566 567 if (c[i] > 11) 568 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} 569 } 570 571#pragma omp parallel for 572 for (int i = 0; i < 10; i++) { 573 for (int j = 0; j < 10; j++) { 574 c[i] = a[i] + b[i]; 575 if (c[i] > 10) { 576 if (c[i] < 20) { 577 break; // OK 578 } 579 } 580 } 581 } 582} 583 584void test_loop_eh() { 585 const int N = 100; 586 float a[N], b[N], c[N]; 587#pragma omp parallel for 588 for (int i = 0; i < 10; i++) { 589 c[i] = a[i] + b[i]; 590 try { 591 for (int j = 0; j < 10; ++j) { 592 if (a[i] > b[j]) 593 throw a[i]; 594 } 595 throw a[i]; 596 } catch (float f) { 597 if (f > 0.1) 598 throw a[i]; 599 return; // expected-error {{cannot return from OpenMP region}} 600 } 601 switch (i) { 602 case 1: 603 b[i]++; 604 break; 605 default: 606 break; 607 } 608 for (int j = 0; j < 10; j++) { 609 if (c[i] > 10) 610 throw c[i]; 611 } 612 } 613 if (c[9] > 10) 614 throw c[9]; // OK 615 616#pragma omp parallel for 617 for (int i = 0; i < 10; ++i) { 618 struct S { 619 void g() { throw 0; } 620 }; 621 } 622} 623 624void test_loop_firstprivate_lastprivate() { 625 S s(4); 626#pragma omp parallel for lastprivate(s) firstprivate(s) 627 for (int i = 0; i < 16; ++i) 628 ; 629} 630