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 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 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 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 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 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 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 parallel for private // expected-error {{expected '(' after 'private'}} 100 for (int k = 0; k < argc; ++k) 101 ++k; 102 #pragma omp 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 parallel for private() // expected-error {{expected expression}} 106 for (int k = 0; k < argc; ++k) 107 ++k; 108 #pragma omp 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 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 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 parallel for private(argc) 118 for (int k = 0; k < argc; ++k) 119 ++k; 120 #pragma omp 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 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 parallel for private(argv[1]) // expected-error {{expected variable name}} 127 for (int k = 0; k < argc; ++k) 128 ++k; 129 #pragma omp parallel for private(e, g) 130 for (int k = 0; k < argc; ++k) 131 ++k; 132 #pragma omp 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 for nowait // expected-error {{unexpected OpenMP clause 'nowait' in directive '#pragma omp parallel for'}} 136 for (int k = 0; k < argc; ++k) 137 ++k; 138 #pragma omp parallel 139 { 140 int v = 0; 141 int i; 142 #pragma omp parallel for private(i) 143 for (int k = 0; k < argc; ++k) { 144 i = k; 145 v += i; 146 } 147 } 148 #pragma omp parallel shared(i) 149 #pragma omp parallel private(i) 150 #pragma omp parallel for private(j) 151 for (int k = 0; k < argc; ++k) 152 ++k; 153 #pragma omp parallel for private(i) 154 for (int k = 0; k < argc; ++k) 155 ++k; 156 return 0; 157 } 158 159 namespace A { 160 double x; 161 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 162 } 163 namespace B { 164 using A::x; 165 } 166 167 int main(int argc, char **argv) { 168 S4 e(4); 169 S5 g(5); 170 S6<float> s6(0.0) , s6_0(1.0); 171 S7<S6<float> > s7(0.0) , s7_0(1.0); 172 int i; 173 int &j = i; 174 #pragma omp parallel for private // expected-error {{expected '(' after 'private'}} 175 for (int k = 0; k < argc; ++k) 176 ++k; 177 #pragma omp parallel for private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 178 for (int k = 0; k < argc; ++k) 179 ++k; 180 #pragma omp parallel for private() // expected-error {{expected expression}} 181 for (int k = 0; k < argc; ++k) 182 ++k; 183 #pragma omp parallel for private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 184 for (int k = 0; k < argc; ++k) 185 ++k; 186 #pragma omp parallel for private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 187 for (int k = 0; k < argc; ++k) 188 ++k; 189 #pragma omp parallel for private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 190 for (int k = 0; k < argc; ++k) 191 ++k; 192 #pragma omp parallel for private(argc) 193 for (int k = 0; k < argc; ++k) 194 ++k; 195 #pragma omp parallel for private(S1) // expected-error {{'S1' does not refer to a value}} 196 for (int k = 0; k < argc; ++k) 197 ++k; 198 #pragma omp parallel for private(a, b) // expected-error {{private variable with incomplete type 'S1'}} 199 for (int k = 0; k < argc; ++k) 200 ++k; 201 #pragma omp parallel for private(argv[1]) // expected-error {{expected variable name}} 202 for (int k = 0; k < argc; ++k) 203 ++k; 204 #pragma omp parallel for private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 205 for (int k = 0; k < argc; ++k) 206 ++k; 207 #pragma omp parallel for private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}} 208 for (int k = 0; k < argc; ++k) 209 ++k; 210 #pragma omp parallel for nowait // expected-error {{unexpected OpenMP clause 'nowait' in directive '#pragma omp parallel for'}} 211 for (int k = 0; k < argc; ++k) 212 ++k; 213 #pragma omp parallel 214 { 215 int i; 216 #pragma omp parallel for private(i) 217 for (int k = 0; k < argc; ++k) 218 ++k; 219 } 220 #pragma omp parallel shared(i) 221 #pragma omp parallel private(i) 222 #pragma omp parallel for private(j) 223 for (int k = 0; k < argc; ++k) 224 ++k; 225 #pragma omp parallel for private(i) 226 for (int k = 0; k < argc; ++k) 227 ++k; 228 static int m; 229 #pragma omp parallel for private(m) 230 for (int k = 0; k < argc; ++k) 231 m = k + 2; 232 233 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}} 234 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}} 235 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}} 236 } 237 238