1 // RUN: %clang_cc1 -verify -fopenmp %s 2 3 void foo() { 4 } 5 6 struct S1; // expected-note 2 {{declared here}} 7 class S2 { 8 mutable int a; 9 10 public: 11 S2() : a(0) {} 12 S2 &operator=(S2 &s2) { return *this; } 13 }; 14 class S3 { 15 int a; 16 17 public: 18 S3() : a(0) {} 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: 27 S4(int v) : a(v) {} 28 }; 29 class S5 { 30 int a; 31 S5() : a(0) {} 32 S5 &operator=(const S5 &s5) { return *this; } // expected-note 3 {{implicitly declared private here}} 33 34 public: 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> 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 void bar(S4 a[2], int n, int b[n]) { 109 #pragma omp single copyprivate(a, b) 110 foo(); 111 } 112 113 namespace A { 114 double x; 115 #pragma omp threadprivate(x) 116 } 117 namespace B { 118 using A::x; 119 } 120 121 int main(int argc, char **argv) { 122 int i; 123 static int intA; 124 #pragma omp parallel 125 #pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}} 126 #pragma omp parallel 127 #pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 128 #pragma omp parallel 129 #pragma omp single copyprivate() // expected-error {{expected expression}} 130 #pragma omp parallel 131 #pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}} 132 #pragma omp parallel 133 #pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 134 #pragma omp parallel 135 #pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 136 #pragma omp parallel 137 #pragma omp single copyprivate(l, B::x) // expected-error {{'operator=' is a private member of 'S4'}} 138 #pragma omp parallel 139 #pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}} 140 #pragma omp parallel 141 #pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}} 142 #pragma omp parallel // expected-note {{implicitly determined as shared}} 143 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} 144 #pragma omp parallel 145 #pragma omp single copyprivate(m) // expected-error {{'operator=' is a private member of 'S5'}} 146 foo(); 147 #pragma omp parallel private(i) 148 { 149 #pragma omp single copyprivate(i) 150 foo(); 151 } 152 #pragma omp parallel shared(i) // expected-note {{defined as shared}} 153 { 154 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} 155 foo(); 156 } 157 #pragma omp parallel private(i) 158 #pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}} 159 { 160 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} 161 foo(); 162 } 163 #pragma omp parallel private(i) 164 #pragma omp parallel // expected-note {{implicitly determined as shared}} 165 { 166 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}} 167 foo(); 168 } 169 #pragma omp parallel 170 #pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}} 171 foo(); 172 #pragma omp parallel 173 #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}} 174 foo(); 175 #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}} 176 foo(); 177 #pragma omp parallel private(intA) 178 { 179 #pragma omp single copyprivate(intA) 180 intA = 99; 181 } 182 183 return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char>' requested here}} 184 } 185 186 extern void abort(void); 187 188 void 189 single(int a, int b) { 190 #pragma omp single copyprivate(a) copyprivate(b) 191 { 192 a = b = 5; 193 } 194 195 if (a != b) 196 abort(); 197 } 198 199 int parallel() { 200 #pragma omp parallel 201 single(1, 2); 202 203 return 0; 204 } 205