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