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