blob: f13bbdb012e2217b69fe42b3697c4d4dd82e4ef6 [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00002
3void foo() {
4}
5
6bool foobool(int argc) {
7 return argc;
8}
9
10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
11extern S1 a;
12class S2 {
13 mutable int a;
14
15public:
16 S2() : a(0) {}
17};
18const S2 b;
19const S2 ba[5];
20class S3 {
21 int a;
22
23public:
24 S3() : a(0) {}
25};
26const S3 ca[5];
Alexey Bataev03b340a2014-10-21 03:16:40 +000027class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000028 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000029 S4(); // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000030
31public:
32 S4(int v) : a(v) {}
33};
Alexey Bataev03b340a2014-10-21 03:16:40 +000034class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000035 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000036 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000037
38public:
39 S5(int v) : a(v) {}
40};
41
42S3 h;
43#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
44
45template <class I, class C>
46int foomain(I argc, C **argv) {
47 I e(4);
48 I g(5);
49 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000050 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000051#pragma omp sections private // expected-error {{expected '(' after 'private'}}
52 {
53 foo();
54 }
55#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
56 {
57 foo();
58 }
59#pragma omp sections private() // expected-error {{expected expression}}
60 {
61 foo();
62 }
63#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
64 {
65 foo();
66 }
67#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
68 {
69 foo();
70 }
71#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
72 {
73 foo();
74 }
75#pragma omp sections private(argc)
76 {
77 foo();
78 }
79#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
80 {
81 foo();
82 }
83#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
84 {
85 foo();
86 }
87#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
88 {
89 foo();
90 }
91#pragma omp sections private(e, g)
92 {
93 foo();
94 }
95#pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
96 {
97 foo();
98 }
99#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
100 {
101 foo();
102 }
103#pragma omp parallel
104 {
105 int v = 0;
106 int i;
107#pragma omp sections private(i)
108 {
109 foo();
110 }
111 v += i;
112 }
113#pragma omp parallel shared(i)
114#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000115#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000116 {
117 foo();
118 }
119#pragma omp sections private(i)
120 {
121 foo();
122 }
123 return 0;
124}
125
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000126namespace A {
127double x;
128#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
129}
130namespace B {
131using A::x;
132}
133
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000134int main(int argc, char **argv) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000135 S4 e(4);
136 S5 g(5);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000137 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000138 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000139#pragma omp sections private // expected-error {{expected '(' after 'private'}}
140 {
141 foo();
142 }
143#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
144 {
145 foo();
146 }
147#pragma omp sections private() // expected-error {{expected expression}}
148 {
149 foo();
150 }
151#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
152 {
153 foo();
154 }
155#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
156 {
157 foo();
158 }
159#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
160 {
161 foo();
162 }
163#pragma omp sections private(argc)
164 {
165 foo();
166 }
167#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
168 {
169 foo();
170 }
171#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
172 {
173 foo();
174 }
175#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
176 {
177 foo();
178 }
Alexey Bataev03b340a2014-10-21 03:16:40 +0000179#pragma omp sections private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000180 {
181 foo();
182 }
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000183#pragma omp sections private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000184 {
185 foo();
186 }
187#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
188 {
189 foo();
190 }
191#pragma omp parallel
192 {
193 int i;
194#pragma omp sections private(i)
195 {
196 foo();
197 }
198 }
199#pragma omp parallel shared(i)
200#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000201#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000202 {
203 foo();
204 }
205#pragma omp sections private(i)
206 {
207 foo();
208 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000209 static int m;
210#pragma omp sections private(m)
211 {
212 foo();
213 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000214
215 return 0;
216}
217