xref: /minix3/external/bsd/llvm/dist/clang/test/OpenMP/sections_private_messages.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1 // RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s
2 
foo()3 void foo() {
4 }
5 
foobool(int argc)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:
S2()16   S2() : a(0) {}
17 };
18 const S2 b;
19 const S2 ba[5];
20 class S3 {
21   int a;
22 
23 public:
S3()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:
S4(int v)32   S4(int v) : a(v) {}
33 };
34 class S5 {
35   int a;
S5()36   S5() : a(0) {} // expected-note {{implicitly declared private here}}
37 
38 public:
S5(int v)39   S5(int v) : a(v) {}
40 };
41 
42 S3 h;
43 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
44 
45 template <class I, class C>
foomain(I argc,C ** argv)46 int foomain(I argc, C **argv) {
47   I e(4);
48   I g(5);
49   int i;
50   int &j = i;                // expected-note {{'j' defined here}}
51 #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)
115 #pragma omp sections private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}}
116   {
117     foo();
118   }
119 #pragma omp sections private(i)
120   {
121     foo();
122   }
123   return 0;
124 }
125 
main(int argc,char ** argv)126 int main(int argc, char **argv) {
127   S4 e(4);
128   S5 g(5);
129   int i;
130   int &j = i;                // expected-note {{'j' defined here}}
131 #pragma omp sections private // expected-error {{expected '(' after 'private'}}
132   {
133     foo();
134   }
135 #pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
136   {
137     foo();
138   }
139 #pragma omp sections private() // expected-error {{expected expression}}
140   {
141     foo();
142   }
143 #pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
144   {
145     foo();
146   }
147 #pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
148   {
149     foo();
150   }
151 #pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
152   {
153     foo();
154   }
155 #pragma omp sections private(argc)
156   {
157     foo();
158   }
159 #pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
160   {
161     foo();
162   }
163 #pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
164   {
165     foo();
166   }
167 #pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
168   {
169     foo();
170   }
171 #pragma omp sections private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
172   {
173     foo();
174   }
175 #pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
176   {
177     foo();
178   }
179 #pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
180   {
181     foo();
182   }
183 #pragma omp parallel
184   {
185     int i;
186 #pragma omp sections private(i)
187     {
188       foo();
189     }
190   }
191 #pragma omp parallel shared(i)
192 #pragma omp parallel private(i)
193 #pragma omp sections private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}}
194   {
195     foo();
196   }
197 #pragma omp sections private(i)
198   {
199     foo();
200   }
201 
202   return 0;
203 }
204 
205