blob: 52d4cb9cdcb653b6cbdccf4839c34e19d283ce85 [file] [log] [blame]
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001// 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
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00004
5void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
11
12struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
13extern S1 a;
14class S2 {
15 mutable int a;
Alexey Bataeva839ddd2016-03-17 10:19:46 +000016 S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000017
18public:
19 S2() : a(0) {}
20 S2(S2 &s2) : a(s2.a) {}
Alexey Bataevdffa93a2015-12-10 08:20:58 +000021 static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000022 static const float S2sc;
23};
24const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}}
Alexey Bataeva839ddd2016-03-17 10:19:46 +000025S2 b; // expected-note 3 {{'b' defined here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000026const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
27class S3 {
28 int a;
29
30public:
Alexey Bataeva1764212015-09-30 09:22:36 +000031 int b;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000032 S3() : a(0) {}
33 S3(const S3 &s3) : a(s3.a) {}
Alexey Bataev794ba0d2015-04-10 10:43:45 +000034 S3 operator+(const S3 &arg1) { return arg1; }
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000035};
Alexey Bataev794ba0d2015-04-10 10:43:45 +000036int operator+(const S3 &arg1, const S3 &arg2) { return 5; }
Alexey Bataeva839ddd2016-03-17 10:19:46 +000037S3 c; // expected-note 3 {{'c' defined here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000038const S3 ca[5]; // expected-note 2 {{'ca' defined here}}
39extern const int f; // expected-note 4 {{'f' declared here}}
Alexey Bataev794ba0d2015-04-10 10:43:45 +000040class S4 {
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000041 int a;
Alexey Bataev794ba0d2015-04-10 10:43:45 +000042 S4(); // expected-note {{implicitly declared private here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000043 S4(const S4 &s4);
Alexey Bataev794ba0d2015-04-10 10:43:45 +000044 S4 &operator+(const S4 &arg) { return (*this); }
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000045
46public:
47 S4(int v) : a(v) {}
48};
49S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; }
50class S5 {
51 int a;
Alexey Bataev794ba0d2015-04-10 10:43:45 +000052 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000053 S5(const S5 &s5) : a(s5.a) {}
Alexey Bataev794ba0d2015-04-10 10:43:45 +000054 S5 &operator+(const S5 &arg);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000055
56public:
57 S5(int v) : a(v) {}
58};
Alexey Bataeva839ddd2016-03-17 10:19:46 +000059class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}}
Charles Lie7cbb3e2015-11-17 20:25:05 +000060#if __cplusplus >= 201103L // C++11 or later
Alexey Bataeva839ddd2016-03-17 10:19:46 +000061// expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}}
Charles Lie7cbb3e2015-11-17 20:25:05 +000062#endif
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000063 int a;
64
65public:
66 S6() : a(6) {}
67 operator int() { return 6; }
Alexey Bataev794ba0d2015-04-10 10:43:45 +000068} o;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000069
70S3 h, k;
71#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
72
73template <class T> // expected-note {{declared here}}
Alexey Bataev794ba0d2015-04-10 10:43:45 +000074T tmain(T argc) {
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000075 const T d = T(); // expected-note 4 {{'d' defined here}}
76 const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}
77 T qa[5] = {T()};
78 T i;
79 T &j = i; // expected-note 4 {{'j' defined here}}
80 S3 &p = k; // expected-note 2 {{'p' defined here}}
81 const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}}
82 T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}}
Alexey Bataev794ba0d2015-04-10 10:43:45 +000083 T fl;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000084#pragma omp parallel sections reduction // expected-error {{expected '(' after 'reduction'}}
85 {
86 foo();
87 }
88#pragma omp parallel sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
89 {
90 foo();
91 }
92#pragma omp parallel sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
93 {
94 foo();
95 }
96#pragma omp parallel sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
97 {
98 foo();
99 }
100#pragma omp parallel sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
101 {
102 foo();
103 }
104#pragma omp parallel sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
105 {
106 foo();
107 }
108#pragma omp parallel sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
109 {
110 foo();
111 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000112#pragma omp parallel sections reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000113 {
114 foo();
115 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000116#pragma omp parallel 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')}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000117 {
118 foo();
119 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000120#pragma omp parallel sections reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000121 {
122 foo();
123 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000124#pragma omp parallel 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'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000125 {
126 foo();
127 }
128#pragma omp parallel sections reduction(&& : argc)
129 {
130 foo();
131 }
132#pragma omp parallel sections reduction(^ : T) // expected-error {{'T' does not refer to a value}}
133 {
134 foo();
135 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000136#pragma omp parallel 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'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000137 {
138 foo();
139 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000140#pragma omp parallel 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}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000141 {
142 foo();
143 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000144#pragma omp parallel sections reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000145 {
146 foo();
147 }
Alexey Bataev1189bd02016-01-26 12:20:39 +0000148#pragma omp parallel sections reduction(+ : ba) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000149 {
150 foo();
151 }
Alexey Bataev1189bd02016-01-26 12:20:39 +0000152#pragma omp parallel sections reduction(* : ca) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000153 {
154 foo();
155 }
Alexey Bataev1189bd02016-01-26 12:20:39 +0000156#pragma omp parallel sections reduction(- : da) // expected-error {{const-qualified list item cannot be reduction}} expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000157 {
158 foo();
159 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000160#pragma omp parallel sections reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000161 {
162 foo();
163 }
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000164#pragma omp parallel sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000165 {
166 foo();
167 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000168#pragma omp parallel sections reduction(&& : S2::S2sc) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000169 {
170 foo();
171 }
172#pragma omp parallel sections reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
173 {
174 foo();
175 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000176#pragma omp parallel sections reduction(+ : o) // expected-error 2 {{no viable overloaded '='}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000177 {
178 foo();
179 }
180#pragma omp parallel sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
181 {
182 foo();
183 }
184#pragma omp parallel private(k)
185#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
186 {
187 foo();
188 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000189#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000190 {
191 foo();
192 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000193#pragma omp parallel sections reduction(+ : r) // expected-error 2 {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000194 {
195 foo();
196 }
197#pragma omp parallel shared(i)
198#pragma omp parallel reduction(min : i)
199#pragma omp parallel sections reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
200 {
201 foo();
202 }
203#pragma omp parallel private(fl)
204#pragma omp parallel sections reduction(+ : fl)
205 {
206 foo();
207 }
208#pragma omp parallel reduction(* : fl)
209#pragma omp parallel sections reduction(+ : fl)
210 {
211 foo();
212 }
213
214 return T();
215}
216
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000217namespace A {
218double x;
219#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
220}
221namespace B {
222using A::x;
223}
224
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000225int main(int argc, char **argv) {
226 const int d = 5; // expected-note 2 {{'d' defined here}}
227 const int da[5] = {0}; // expected-note {{'da' defined here}}
228 int qa[5] = {0};
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000229 S4 e(4);
230 S5 g(5);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000231 int i;
232 int &j = i; // expected-note 2 {{'j' defined here}}
233 S3 &p = k; // expected-note 2 {{'p' defined here}}
234 const int &r = da[i]; // expected-note {{'r' defined here}}
235 int &q = qa[i]; // expected-note {{'q' defined here}}
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000236 float fl;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000237#pragma omp parallel sections reduction // expected-error {{expected '(' after 'reduction'}}
238 {
239 foo();
240 }
241#pragma omp parallel sections reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
242 {
243 foo();
244 }
245#pragma omp parallel sections reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
246 {
247 foo();
248 }
249#pragma omp parallel sections reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
250 {
251 foo();
252 }
253#pragma omp parallel sections reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
254 {
255 foo();
256 }
257#pragma omp parallel sections reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}}
258 {
259 foo();
260 }
261#pragma omp parallel sections reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
262 {
263 foo();
264 }
265#pragma omp parallel sections reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
266 {
267 foo();
268 }
269#pragma omp parallel sections reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
270 {
271 foo();
272 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000273#pragma omp parallel sections reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000274 {
275 foo();
276 }
277#pragma omp parallel sections reduction(~ : argc) // expected-error {{expected unqualified-id}}
278 {
279 foo();
280 }
281#pragma omp parallel sections reduction(&& : argc)
282 {
283 foo();
284 }
285#pragma omp parallel sections reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
286 {
287 foo();
288 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000289#pragma omp parallel 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'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000290 {
291 foo();
292 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000293#pragma omp parallel 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}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000294 {
295 foo();
296 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000297#pragma omp parallel sections reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000298 {
299 foo();
300 }
Alexey Bataev1189bd02016-01-26 12:20:39 +0000301#pragma omp parallel sections reduction(+ : ba) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000302 {
303 foo();
304 }
Alexey Bataev1189bd02016-01-26 12:20:39 +0000305#pragma omp parallel sections reduction(* : ca) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000306 {
307 foo();
308 }
Alexey Bataev1189bd02016-01-26 12:20:39 +0000309#pragma omp parallel sections reduction(- : da) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000310 {
311 foo();
312 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000313#pragma omp parallel sections reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000314 {
315 foo();
316 }
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000317#pragma omp parallel sections reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000318 {
319 foo();
320 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000321#pragma omp parallel sections reduction(&& : S2::S2sc) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000322 {
323 foo();
324 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000325#pragma omp parallel 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')}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000326 {
327 foo();
328 }
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000329#pragma omp parallel sections reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000330 {
331 foo();
332 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000333#pragma omp parallel sections reduction(+ : o) // expected-error {{no viable overloaded '='}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000334 {
335 foo();
336 }
337#pragma omp parallel sections private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
338 {
339 foo();
340 }
341#pragma omp parallel private(k)
342#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
343 {
344 foo();
345 }
346#pragma omp parallel sections reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}}
347 {
348 foo();
349 }
Alexey Bataeva1764212015-09-30 09:22:36 +0000350#pragma omp parallel sections reduction(+ : r) // expected-error {{const-qualified list item cannot be reduction}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000351 {
352 foo();
353 }
354#pragma omp parallel shared(i)
355#pragma omp parallel reduction(min : i)
356#pragma omp parallel sections reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}}
357 {
358 foo();
359 }
360#pragma omp parallel private(fl)
361#pragma omp parallel sections reduction(+ : fl)
362 {
363 foo();
364 }
365#pragma omp parallel reduction(* : fl)
366#pragma omp parallel sections reduction(+ : fl)
367 {
368 foo();
369 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000370 static int m;
371#pragma omp parallel sections reduction(+ : m) // OK
372 {
373 foo();
374 }
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000375
376 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}}
377}