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