1 // RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s
2
foo()3 void foo() {
4 }
5
6 struct S1; // expected-note 2 {{declared here}}
7 class S2 {
8 mutable int a;
9
10 public:
S2()11 S2() : a(0) {}
operator =(S2 & s2)12 S2 &operator=(S2 &s2) { return *this; }
13 };
14 class S3 {
15 int a;
16
17 public:
S3()18 S3() : a(0) {}
operator =(S3 & s3)19 S3 &operator=(S3 &s3) { return *this; }
20 };
21 class S4 {
22 int a;
23 S4();
24 S4 &operator=(const S4 &s4); // expected-note 3 {{implicitly declared private here}}
25
26 public:
S4(int v)27 S4(int v) : a(v) {}
28 };
29 class S5 {
30 int a;
S5()31 S5() : a(0) {}
operator =(const S5 & s5)32 S5 &operator=(const S5 &s5) { return *this; } // expected-note 3 {{implicitly declared private here}}
33
34 public:
S5(int v)35 S5(int v) : a(v) {}
36 };
37
38 S2 k;
39 S3 h;
40 S4 l(3);
41 S5 m(4);
42 #pragma omp threadprivate(h, k, l, m)
43
44 template <class T, class C>
tmain(T argc,C ** argv)45 T tmain(T argc, C **argv) {
46 T i;
47 static T TA;
48 #pragma omp parallel
49 #pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}}
50 #pragma omp parallel
51 #pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
52 #pragma omp parallel
53 #pragma omp single copyprivate() // expected-error {{expected expression}}
54 #pragma omp parallel
55 #pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
56 #pragma omp parallel
57 #pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
58 #pragma omp parallel
59 #pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
60 #pragma omp parallel
61 #pragma omp single copyprivate(l) // expected-error 2 {{'operator=' is a private member of 'S4'}}
62 #pragma omp parallel
63 #pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}}
64 #pragma omp parallel
65 #pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}}
66 #pragma omp parallel // expected-note {{implicitly determined as shared}}
67 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
68 #pragma omp parallel
69 #pragma omp single copyprivate(m) // expected-error 2 {{'operator=' is a private member of 'S5'}}
70 foo();
71 #pragma omp parallel private(i)
72 {
73 #pragma omp single copyprivate(i)
74 foo();
75 }
76 #pragma omp parallel shared(i) // expected-note {{defined as shared}}
77 {
78 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
79 foo();
80 }
81 #pragma omp parallel private(i)
82 #pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}}
83 {
84 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
85 foo();
86 }
87 #pragma omp parallel private(i)
88 #pragma omp parallel // expected-note {{implicitly determined as shared}}
89 {
90 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
91 foo();
92 }
93 #pragma omp parallel
94 #pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}}
95 foo();
96 #pragma omp parallel
97 #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}}
98 foo();
99 #pragma omp parallel private(TA)
100 {
101 #pragma omp single copyprivate(TA)
102 TA = 99;
103 }
104
105 return T();
106 }
107
108 namespace A {
109 double x;
110 #pragma omp threadprivate(x)
111 }
112 namespace B {
113 using A::x;
114 }
115
main(int argc,char ** argv)116 int main(int argc, char **argv) {
117 int i;
118 static int intA;
119 #pragma omp parallel
120 #pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}}
121 #pragma omp parallel
122 #pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
123 #pragma omp parallel
124 #pragma omp single copyprivate() // expected-error {{expected expression}}
125 #pragma omp parallel
126 #pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
127 #pragma omp parallel
128 #pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
129 #pragma omp parallel
130 #pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
131 #pragma omp parallel
132 #pragma omp single copyprivate(l, B::x) // expected-error {{'operator=' is a private member of 'S4'}}
133 #pragma omp parallel
134 #pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}}
135 #pragma omp parallel
136 #pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}}
137 #pragma omp parallel // expected-note {{implicitly determined as shared}}
138 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
139 #pragma omp parallel
140 #pragma omp single copyprivate(m) // expected-error {{'operator=' is a private member of 'S5'}}
141 foo();
142 #pragma omp parallel private(i)
143 {
144 #pragma omp single copyprivate(i)
145 foo();
146 }
147 #pragma omp parallel shared(i) // expected-note {{defined as shared}}
148 {
149 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
150 foo();
151 }
152 #pragma omp parallel private(i)
153 #pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}}
154 {
155 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
156 foo();
157 }
158 #pragma omp parallel private(i)
159 #pragma omp parallel // expected-note {{implicitly determined as shared}}
160 {
161 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
162 foo();
163 }
164 #pragma omp parallel
165 #pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}}
166 foo();
167 #pragma omp parallel
168 #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}}
169 foo();
170 #pragma omp single copyprivate(i) nowait // expected-error {{the 'copyprivate' clause must not be used with the 'nowait' clause}} expected-note {{'nowait' clause is here}}
171 foo();
172 #pragma omp parallel private(intA)
173 {
174 #pragma omp single copyprivate(intA)
175 intA = 99;
176 }
177
178 return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char>' requested here}}
179 }
180
181 extern void abort(void);
182
183 void
single(int a,int b)184 single(int a, int b) {
185 #pragma omp single copyprivate(a) copyprivate(b)
186 {
187 a = b = 5;
188 }
189
190 if (a != b)
191 abort();
192 }
193
parallel()194 int parallel() {
195 #pragma omp parallel
196 single(1, 2);
197
198 return 0;
199 }
200