1 // RUN: %clang_cc1 -verify -fopenmp %s
2 // RUN: %clang_cc1 -verify -fopenmp -std=c++98 %s
3 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 %s
4 
5 void foo() {
6 }
7 
8 #if __cplusplus >= 201103L
9 // expected-note@+2 4 {{declared here}}
10 #endif
11 bool foobool(int argc) {
12   return argc;
13 }
14 
15 struct S1; // expected-note {{declared here}}
16 
17 template <class T, typename S, int N, int ST> // expected-note {{declared here}}
18 T tmain(T argc, S **argv) {                   //expected-note 2 {{declared here}}
19 #pragma omp for ordered
20   for (int i = ST; i < N; i++)
21     argv[0][i] = argv[0][i] - argv[0][i - ST];
22 #pragma omp for ordered( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
23   for (int i = ST; i < N; i++)
24     argv[0][i] = argv[0][i] - argv[0][i - ST];
25 #pragma omp for ordered() // expected-error {{expected expression}}
26   for (int i = ST; i < N; i++)
27     argv[0][i] = argv[0][i] - argv[0][i - ST];
28 // expected-error@+3 {{expected ')'}} expected-note@+3 {{to match this '('}}
29 // expected-error@+2 2 {{expression is not an integral constant expression}}
30 // expected-note@+1 2 {{read of non-const variable 'argc' is not allowed in a constant expression}}
31 #pragma omp for ordered(argc
32   for (int i = ST; i < N; i++)
33     argv[0][i] = argv[0][i] - argv[0][i - ST];
34 // expected-error@+1 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
35 #pragma omp for ordered(ST // expected-error {{expected ')'}} expected-note {{to match this '('}}
36   for (int i = ST; i < N; i++)
37     argv[0][i] = argv[0][i] - argv[0][i - ST];
38 #pragma omp for ordered(1)) // expected-warning {{extra tokens at the end of '#pragma omp for' are ignored}}
39   for (int i = ST; i < N; i++)
40     argv[0][i] = argv[0][i] - argv[0][i - ST];
41 #pragma omp for ordered((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'ordered' clause}}
42   for (int i = ST; i < N; i++)
43     argv[0][i] = argv[0][i] - argv[0][i - ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp for', but found only 1}}
44 // expected-error@+6 2 {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}}
45 // expected-error@+5 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
46 // expected-error@+4 2 {{expression is not an integral constant expression}}
47 #if __cplusplus >= 201103L
48 // expected-note@+2 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
49 #endif
50 #pragma omp for ordered(foobool(argc)), ordered(true), ordered(-5)
51   for (int i = ST; i < N; i++)
52     argv[0][i] = argv[0][i] - argv[0][i - ST];
53 #pragma omp for ordered(S) // expected-error {{'S' does not refer to a value}}
54   for (int i = ST; i < N; i++)
55     argv[0][i] = argv[0][i] - argv[0][i - ST];
56 #if __cplusplus <= 199711L
57 // expected-error@+4 2 {{expression is not an integral constant expression}}
58 #else
59 // expected-error@+2 2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
60 #endif
61 #pragma omp for ordered(argv[1] = 2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
62   for (int i = ST; i < N; i++)
63     argv[0][i] = argv[0][i] - argv[0][i - ST];
64 #pragma omp for ordered(1)
65   for (int i = ST; i < N; i++)
66     argv[0][i] = argv[0][i] - argv[0][i - ST];
67 #pragma omp for ordered(N-1) // expected-error 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
68   for (int i = ST; i < N; i++)
69     argv[0][i] = argv[0][i] - argv[0][i - ST];
70 #pragma omp for ordered(N) // expected-error {{argument to 'ordered' clause must be a strictly positive integer value}}
71   for (T i = ST; i < N; i++)
72     argv[0][i] = argv[0][i] - argv[0][i - ST];
73 #pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
74   foo();                    // expected-error {{expected 2 for loops after '#pragma omp for'}}
75 #pragma omp for ordered(N) collapse(N + 2) // expected-error {{the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause}} expected-note {{parameter of the 'collapse' clause}} expected-error {{argument to 'ordered' clause must be a strictly positive integer value}}
76   for (int i = ST; i < N; i++)
77     for (int j = ST; j < N; j++)
78       for (int k = ST; k < N; k++)
79         foo();
80   return argc;
81 }
82 
83 int main(int argc, char **argv) {
84 #pragma omp for ordered
85   for (int i = 4; i < 12; i++)
86     argv[0][i] = argv[0][i] - argv[0][i - 4];
87 #pragma omp for ordered( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
88   for (int i = 4; i < 12; i++)
89     argv[0][i] = argv[0][i] - argv[0][i - 4];
90 #pragma omp for ordered() // expected-error {{expected expression}}
91   for (int i = 4; i < 12; i++)
92     argv[0][i] = argv[0][i] - argv[0][i - 4];
93 #pragma omp for ordered(4 // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{as specified in 'ordered' clause}}
94   for (int i = 4; i < 12; i++)
95     argv[0][i] = argv[0][i] - argv[0][i - 4]; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
96 #pragma omp for ordered(2 + 2))              // expected-warning {{extra tokens at the end of '#pragma omp for' are ignored}}  expected-note {{as specified in 'ordered' clause}}
97   for (int i = 4; i < 12; i++)
98     argv[0][i] = argv[0][i] - argv[0][i - 4];    // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
99 // expected-error@+4 {{expression is not an integral constant expression}}
100 #if __cplusplus >= 201103L
101 // expected-note@+2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
102 #endif
103 #pragma omp for ordered(foobool(1) > 0 ? 1 : 2)
104   for (int i = 4; i < 12; i++)
105     argv[0][i] = argv[0][i] - argv[0][i - 4];
106 // expected-error@+6 {{expression is not an integral constant expression}}
107 #if __cplusplus >= 201103L
108 // expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
109 #endif
110 // expected-error@+2 2 {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}}
111 // expected-error@+1 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
112 #pragma omp for ordered(foobool(argc)), ordered(true), ordered(-5)
113   for (int i = 4; i < 12; i++)
114     argv[0][i] = argv[0][i] - argv[0][i - 4];
115 #pragma omp for ordered(S1) // expected-error {{'S1' does not refer to a value}}
116   for (int i = 4; i < 12; i++)
117     argv[0][i] = argv[0][i] - argv[0][i - 4];
118 #if __cplusplus <= 199711L
119 // expected-error@+4 {{expression is not an integral constant expression}}
120 #else
121 // expected-error@+2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
122 #endif
123 #pragma omp for ordered(argv[1] = 2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
124   for (int i = 4; i < 12; i++)
125     argv[0][i] = argv[0][i] - argv[0][i - 4];
126 // expected-error@+3 {{statement after '#pragma omp for' must be a for loop}}
127 // expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, -1, -2>' requested here}}
128 #pragma omp for ordered(ordered(tmain < int, char, -1, -2 > (argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
129   foo();
130 #pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
131   foo();                    // expected-error {{expected 2 for loops after '#pragma omp for'}}
132 #pragma omp for ordered(0)              // expected-error {{argument to 'ordered' clause must be a strictly positive integer value}}
133   for (int i = 4; i < 12; i++)
134     argv[0][i] = argv[0][i] - argv[0][i - 4];
135 #pragma omp for ordered(2) collapse(3) // expected-error {{the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause}} expected-note {{parameter of the 'collapse' clause}}
136   for (int i = 0; i < 10; i++)
137     for (int j = 0; j < 11; j++)
138       for (int k = 0; k < 12; k++)
139         foo();
140   // expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, 1, 0>' requested here}}
141   return tmain<int, char, 1, 0>(argc, argv);
142 }
143 
144