Clang Project

clang_source_code/test/OpenMP/sections_private_messages.cpp
1// RUN: %clang_cc1 -verify -fopenmp %s
2
3// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
5extern int omp_default_mem_alloc;
6void foo() {
7}
8
9bool foobool(int argc) {
10  return argc;
11}
12
13struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
14extern S1 a;
15class S2 {
16  mutable int a;
17
18public:
19  S2() : a(0) {}
20};
21const S2 b;
22const S2 ba[5];
23class S3 {
24  int a;
25
26public:
27  S3() : a(0) {}
28};
29const S3 ca[5];
30class S4 {
31  int a;
32  S4(); // expected-note {{implicitly declared private here}}
33
34public:
35  S4(int v) : a(v) {
36#pragma omp sections private(a) private(this->a)
37    {
38      for (int k = 0; k < v; ++k)
39        ++this->a;
40    }
41  }
42};
43class S5 {
44  int a;
45  S5() : a(0) {} // expected-note {{implicitly declared private here}}
46
47public:
48  S5(int v) : a(v) {}
49  S5 &operator=(S5 &s) {
50#pragma omp sections private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
51    {
52      for (int k = 0; k < s.a; ++k)
53        ++s.a;
54    }
55    return *this;
56  }
57};
58
59template <typename T>
60class S6 {
61public:
62  T a;
63
64  S6() : a(0) {}
65  S6(T v) : a(v) {
66#pragma omp sections private(a) private(this->a)
67    {
68      for (int k = 0; k < v; ++k)
69        ++this->a;
70    }
71  }
72  S6 &operator=(S6 &s) {
73#pragma omp sections private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
74    {
75      for (int k = 0; k < s.a; ++k)
76        ++s.a;
77    }
78    return *this;
79  }
80};
81
82template <typename T>
83class S7 : public T {
84  T a;
85  S7() : a(0) {}
86
87public:
88  S7(T v) : a(v) {
89#pragma omp sections private(a) private(this->a) private(T::a)
90    {
91      for (int k = 0; k < a.a; ++k)
92        ++this->a.a;
93    }
94  }
95  S7 &operator=(S7 &s) {
96#pragma omp sections private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
97    {
98      for (int k = 0; k < s.a.a; ++k)
99        ++s.a.a;
100    }
101    return *this;
102  }
103};
104
105S3 h;
106#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
107
108template <class I, class C>
109int foomain(I argc, C **argv) {
110  I e(4);
111  I g(5);
112  int i;
113  int &j = i;
114#pragma omp sections private // expected-error {{expected '(' after 'private'}}
115  {
116    foo();
117  }
118#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
119  {
120    foo();
121  }
122#pragma omp sections private() // expected-error {{expected expression}}
123  {
124    foo();
125  }
126#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
127  {
128    foo();
129  }
130#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
131  {
132    foo();
133  }
134#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
135  {
136    foo();
137  }
138#pragma omp sections private(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
139  {
140    foo();
141  }
142#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
143  {
144    foo();
145  }
146#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
147  {
148    foo();
149  }
150#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
151  {
152    foo();
153  }
154#pragma omp sections private(e, g)
155  {
156    foo();
157  }
158#pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
159  {
160    foo();
161  }
162#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
163  {
164    foo();
165  }
166#pragma omp parallel
167  {
168    int v = 0;
169    int i;
170#pragma omp sections private(i)
171    {
172      foo();
173    }
174    v += i;
175  }
176#pragma omp parallel shared(i)
177#pragma omp parallel private(i)
178#pragma omp sections private(j)
179  {
180    foo();
181  }
182#pragma omp sections private(i)
183  {
184    foo();
185  }
186  return 0;
187}
188
189namespace A {
190double x;
191#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
192}
193namespace B {
194using A::x;
195}
196
197int main(int argc, char **argv) {
198  S4 e(4);
199  S5 g(5);
200  S6<float> s6(0.0) , s6_0(1.0);
201  S7<S6<float> > s7(0.0) , s7_0(1.0);
202  int i;
203  int &j = i;
204#pragma omp sections private // expected-error {{expected '(' after 'private'}}
205  {
206    foo();
207  }
208#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
209  {
210    foo();
211  }
212#pragma omp sections private() // expected-error {{expected expression}}
213  {
214    foo();
215  }
216#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
217  {
218    foo();
219  }
220#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
221  {
222    foo();
223  }
224#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
225  {
226    foo();
227  }
228#pragma omp sections private(argc)
229  {
230    foo();
231  }
232#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
233  {
234    foo();
235  }
236#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
237  {
238    foo();
239  }
240#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
241  {
242    foo();
243  }
244#pragma omp sections private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
245  {
246    foo();
247  }
248#pragma omp sections private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
249  {
250    foo();
251  }
252#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
253  {
254    foo();
255  }
256#pragma omp parallel
257  {
258    int i;
259#pragma omp sections private(i)
260    {
261      foo();
262    }
263  }
264#pragma omp parallel shared(i)
265#pragma omp parallel private(i)
266#pragma omp sections private(j)
267  {
268    foo();
269  }
270#pragma omp sections private(i)
271  {
272    foo();
273  }
274  static int m;
275#pragma omp sections private(m)
276  {
277    foo();
278  }
279
280  s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
281  s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
282  return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
283}
284
285