John McCall | 161755a | 2010-04-06 21:38:20 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s |
| 2 | |
| 3 | namespace test0 { |
| 4 | class A { |
| 5 | protected: int x; // expected-note 3 {{declared}} |
| 6 | static int sx; // expected-note 3 {{declared}} |
| 7 | }; |
| 8 | class B : public A { |
| 9 | }; |
| 10 | class C : protected A { // expected-note {{declared}} |
| 11 | }; |
| 12 | class D : private B { // expected-note 3 {{constrained}} |
| 13 | }; |
| 14 | |
| 15 | void test(A &a) { |
| 16 | (void) a.x; // expected-error {{'x' is a protected member}} |
| 17 | (void) a.sx; // expected-error {{'sx' is a protected member}} |
| 18 | } |
| 19 | void test(B &b) { |
| 20 | (void) b.x; // expected-error {{'x' is a protected member}} |
| 21 | (void) b.sx; // expected-error {{'sx' is a protected member}} |
| 22 | } |
| 23 | void test(C &c) { |
| 24 | (void) c.x; // expected-error {{'x' is a protected member}} expected-error {{protected base class}} |
| 25 | (void) c.sx; // expected-error {{'sx' is a protected member}} |
| 26 | } |
| 27 | void test(D &d) { |
| 28 | (void) d.x; // expected-error {{'x' is a private member}} expected-error {{private base class}} |
| 29 | (void) d.sx; // expected-error {{'sx' is a private member}} |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | namespace test1 { |
| 34 | class A { |
| 35 | protected: int x; |
| 36 | static int sx; |
| 37 | static void test(A&); |
| 38 | }; |
| 39 | class B : public A { |
| 40 | static void test(B&); |
| 41 | }; |
| 42 | class C : protected A { |
| 43 | static void test(C&); |
| 44 | }; |
| 45 | class D : private B { |
| 46 | static void test(D&); |
| 47 | }; |
| 48 | |
| 49 | void A::test(A &a) { |
| 50 | (void) a.x; |
| 51 | (void) a.sx; |
| 52 | } |
| 53 | void B::test(B &b) { |
| 54 | (void) b.x; |
| 55 | (void) b.sx; |
| 56 | } |
| 57 | void C::test(C &c) { |
| 58 | (void) c.x; |
| 59 | (void) c.sx; |
| 60 | } |
| 61 | void D::test(D &d) { |
| 62 | (void) d.x; |
| 63 | (void) d.sx; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | namespace test2 { |
| 68 | class A { |
| 69 | protected: int x; // expected-note 3 {{declared}} |
| 70 | static int sx; |
| 71 | static void test(A&); |
| 72 | }; |
| 73 | class B : public A { |
| 74 | static void test(A&); |
| 75 | }; |
| 76 | class C : protected A { |
| 77 | static void test(A&); |
| 78 | }; |
| 79 | class D : private B { |
| 80 | static void test(A&); |
| 81 | }; |
| 82 | |
| 83 | void A::test(A &a) { |
| 84 | (void) a.x; |
| 85 | (void) a.sx; |
| 86 | } |
| 87 | void B::test(A &a) { |
| 88 | (void) a.x; // expected-error {{'x' is a protected member}} |
| 89 | (void) a.sx; |
| 90 | } |
| 91 | void C::test(A &a) { |
| 92 | (void) a.x; // expected-error {{'x' is a protected member}} |
| 93 | (void) a.sx; |
| 94 | } |
| 95 | void D::test(A &a) { |
| 96 | (void) a.x; // expected-error {{'x' is a protected member}} |
| 97 | (void) a.sx; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | namespace test3 { |
| 102 | class B; |
| 103 | class A { |
| 104 | protected: int x; // expected-note {{declared}} |
| 105 | static int sx; |
| 106 | static void test(B&); |
| 107 | }; |
| 108 | class B : public A { |
| 109 | static void test(B&); |
| 110 | }; |
| 111 | class C : protected A { |
| 112 | static void test(B&); |
| 113 | }; |
| 114 | class D : private B { |
| 115 | static void test(B&); |
| 116 | }; |
| 117 | |
| 118 | void A::test(B &b) { |
| 119 | (void) b.x; |
| 120 | (void) b.sx; |
| 121 | } |
| 122 | void B::test(B &b) { |
| 123 | (void) b.x; |
| 124 | (void) b.sx; |
| 125 | } |
| 126 | void C::test(B &b) { |
| 127 | (void) b.x; // expected-error {{'x' is a protected member}} |
| 128 | (void) b.sx; |
| 129 | } |
| 130 | void D::test(B &b) { |
| 131 | (void) b.x; |
| 132 | (void) b.sx; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | namespace test4 { |
| 137 | class C; |
| 138 | class A { |
| 139 | protected: int x; // expected-note 2 {{declared}} |
| 140 | static int sx; |
| 141 | static void test(C&); |
| 142 | }; |
| 143 | class B : public A { |
| 144 | static void test(C&); |
| 145 | }; |
| 146 | class C : protected A { // expected-note 4 {{constrained}} expected-note 3 {{declared}} |
| 147 | static void test(C&); |
| 148 | }; |
| 149 | class D : private B { |
| 150 | static void test(C&); |
| 151 | }; |
| 152 | |
| 153 | void A::test(C &c) { |
| 154 | (void) c.x; // expected-error {{'x' is a protected member}} \ |
| 155 | // expected-error {{protected base class}} |
| 156 | (void) c.sx; // expected-error {{'sx' is a protected member}} |
| 157 | } |
| 158 | void B::test(C &c) { |
| 159 | (void) c.x; // expected-error {{'x' is a protected member}} \ |
| 160 | // expected-error {{protected base class}} |
| 161 | (void) c.sx; // expected-error {{'sx' is a protected member}} |
| 162 | } |
| 163 | void C::test(C &c) { |
| 164 | (void) c.x; |
| 165 | (void) c.sx; |
| 166 | } |
| 167 | void D::test(C &c) { |
| 168 | (void) c.x; // expected-error {{'x' is a protected member}} \ |
| 169 | // expected-error {{protected base class}} |
| 170 | (void) c.sx; // expected-error {{'sx' is a protected member}} |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | namespace test5 { |
| 175 | class D; |
| 176 | class A { |
| 177 | protected: int x; |
| 178 | static int sx; |
| 179 | static void test(D&); |
| 180 | }; |
| 181 | class B : public A { |
| 182 | static void test(D&); |
| 183 | }; |
| 184 | class C : protected A { |
| 185 | static void test(D&); |
| 186 | }; |
| 187 | class D : private B { // expected-note 9 {{constrained}} |
| 188 | static void test(D&); |
| 189 | }; |
| 190 | |
| 191 | void A::test(D &d) { |
| 192 | (void) d.x; // expected-error {{'x' is a private member}} \ |
| 193 | // expected-error {{cannot cast}} |
| 194 | (void) d.sx; // expected-error {{'sx' is a private member}} |
| 195 | } |
| 196 | void B::test(D &d) { |
| 197 | (void) d.x; // expected-error {{'x' is a private member}} \ |
| 198 | // expected-error {{cannot cast}} |
| 199 | (void) d.sx; // expected-error {{'sx' is a private member}} |
| 200 | } |
| 201 | void C::test(D &d) { |
| 202 | (void) d.x; // expected-error {{'x' is a private member}} \ |
| 203 | // expected-error {{cannot cast}} |
| 204 | (void) d.sx; // expected-error {{'sx' is a private member}} |
| 205 | } |
| 206 | void D::test(D &d) { |
| 207 | (void) d.x; |
| 208 | (void) d.sx; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | namespace test6 { |
| 213 | class Static {}; |
| 214 | class A { |
| 215 | protected: |
| 216 | void foo(int); // expected-note 3 {{declared}} |
| 217 | void foo(long); |
| 218 | static void foo(Static); |
| 219 | |
| 220 | static void test(A&); |
| 221 | }; |
| 222 | class B : public A { |
| 223 | static void test(A&); |
| 224 | }; |
| 225 | class C : protected A { |
| 226 | static void test(A&); |
| 227 | }; |
| 228 | class D : private B { |
| 229 | static void test(A&); |
| 230 | }; |
| 231 | |
| 232 | void A::test(A &a) { |
| 233 | a.foo(10); |
| 234 | a.foo(Static()); |
| 235 | } |
| 236 | void B::test(A &a) { |
| 237 | a.foo(10); // expected-error {{'foo' is a protected member}} |
| 238 | a.foo(Static()); |
| 239 | } |
| 240 | void C::test(A &a) { |
| 241 | a.foo(10); // expected-error {{'foo' is a protected member}} |
| 242 | a.foo(Static()); |
| 243 | } |
| 244 | void D::test(A &a) { |
| 245 | a.foo(10); // expected-error {{'foo' is a protected member}} |
| 246 | a.foo(Static()); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | namespace test7 { |
| 251 | class Static {}; |
| 252 | class A { |
| 253 | protected: |
| 254 | void foo(int); // expected-note 3 {{declared}} |
| 255 | void foo(long); |
| 256 | static void foo(Static); |
| 257 | |
| 258 | static void test(); |
| 259 | }; |
| 260 | class B : public A { |
| 261 | static void test(); |
| 262 | }; |
| 263 | class C : protected A { |
| 264 | static void test(); |
| 265 | }; |
| 266 | class D : private B { |
| 267 | static void test(); |
| 268 | }; |
| 269 | |
| 270 | void A::test() { |
| 271 | void (A::*x)(int) = &A::foo; |
| 272 | void (*sx)(Static) = &A::foo; |
| 273 | } |
| 274 | void B::test() { |
| 275 | void (A::*x)(int) = &A::foo; // expected-error {{'foo' is a protected member}} |
| 276 | void (*sx)(Static) = &A::foo; |
| 277 | } |
| 278 | void C::test() { |
| 279 | void (A::*x)(int) = &A::foo; // expected-error {{'foo' is a protected member}} |
| 280 | void (*sx)(Static) = &A::foo; |
| 281 | } |
| 282 | void D::test() { |
| 283 | void (A::*x)(int) = &A::foo; // expected-error {{'foo' is a protected member}} |
| 284 | void (*sx)(Static) = &A::foo; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | namespace test8 { |
| 289 | class Static {}; |
| 290 | class A { |
| 291 | protected: |
| 292 | void foo(int); // expected-note 3 {{declared}} |
| 293 | void foo(long); |
| 294 | static void foo(Static); |
| 295 | |
| 296 | static void test(); |
| 297 | }; |
| 298 | class B : public A { |
| 299 | static void test(); |
| 300 | }; |
| 301 | class C : protected A { |
| 302 | static void test(); |
| 303 | }; |
| 304 | class D : private B { |
| 305 | static void test(); |
| 306 | }; |
| 307 | void call(void (A::*)(int)); |
| 308 | void calls(void (*)(Static)); |
| 309 | |
| 310 | void A::test() { |
| 311 | call(&A::foo); |
| 312 | calls(&A::foo); |
| 313 | } |
| 314 | void B::test() { |
| 315 | call(&A::foo); // expected-error {{'foo' is a protected member}} |
| 316 | calls(&A::foo); |
| 317 | } |
| 318 | void C::test() { |
| 319 | call(&A::foo); // expected-error {{'foo' is a protected member}} |
| 320 | calls(&A::foo); |
| 321 | } |
| 322 | void D::test() { |
| 323 | call(&A::foo); // expected-error {{'foo' is a protected member}} |
| 324 | calls(&A::foo); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | namespace test9 { |
| 329 | class A { |
| 330 | protected: int foo(); // expected-note 8 {{declared}} |
| 331 | }; |
| 332 | |
| 333 | class B : public A { |
| 334 | friend class D; |
| 335 | }; |
| 336 | |
| 337 | class C : protected B { // expected-note {{declared}} \ |
| 338 | // expected-note 6 {{constrained}} |
| 339 | }; |
| 340 | |
| 341 | class D : public A { |
| 342 | static void test(A &a) { |
| 343 | a.foo(); // expected-error {{'foo' is a protected member}} |
| 344 | a.A::foo(); // expected-error {{'foo' is a protected member}} |
| 345 | a.B::foo(); |
| 346 | a.C::foo(); // expected-error {{'foo' is a protected member}} |
| 347 | } |
| 348 | |
| 349 | static void test(B &b) { |
| 350 | b.foo(); |
| 351 | b.A::foo(); // expected-error {{'foo' is a protected member}} |
| 352 | b.B::foo(); |
| 353 | b.C::foo(); // expected-error {{'foo' is a protected member}} |
| 354 | } |
| 355 | |
| 356 | static void test(C &c) { |
| 357 | c.foo(); // expected-error {{'foo' is a protected member}} \ |
| 358 | // expected-error {{cannot cast}} |
| 359 | c.A::foo(); // expected-error {{'foo' is a protected member}} \ |
| 360 | // expected-error {{'A' is a protected member}} \ |
| 361 | // expected-error {{cannot cast}} |
| 362 | c.B::foo(); // expected-error {{'B' is a protected member}} \ |
| 363 | // expected-error {{cannot cast}} |
| 364 | c.C::foo(); // expected-error {{'foo' is a protected member}} \ |
| 365 | // expected-error {{cannot cast}} |
| 366 | } |
| 367 | |
| 368 | static void test(D &d) { |
| 369 | d.foo(); |
| 370 | d.A::foo(); |
| 371 | d.B::foo(); |
| 372 | d.C::foo(); // expected-error {{'foo' is a protected member}} |
| 373 | } |
| 374 | }; |
| 375 | } |
| 376 | |
| 377 | namespace test10 { |
| 378 | template<typename T> class A { |
| 379 | protected: |
| 380 | int foo(); |
| 381 | int foo() const; |
| 382 | |
| 383 | ~A() { foo(); } |
| 384 | }; |
| 385 | |
| 386 | template class A<int>; |
| 387 | } |