blob: 3f4397a28b4bf6cebb88c1b7fe2a54bb3397fbc3 [file] [log] [blame]
John McCallc373d482010-01-27 01:50:18 +00001// RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s
2
3// C++0x [class.access]p4:
4
5// Access control is applied uniformly to all names, whether the
6// names are referred to from declarations or expressions. In the
7// case of overloaded function names, access control is applied to
8// the function selected by overload resolution.
9
10class Public {} PublicInst;
11class Protected {} ProtectedInst;
12class Private {} PrivateInst;
13
14namespace test0 {
15 class A {
16 public:
17 void foo(Public&);
18 protected:
19 void foo(Protected&); // expected-note 2 {{declared protected here}}
20 private:
21 void foo(Private&); // expected-note 2 {{declared private here}}
22 };
23
24 void test(A *op) {
25 op->foo(PublicInst);
26 op->foo(ProtectedInst); // expected-error {{access to protected member outside any class}}
27 op->foo(PrivateInst); // expected-error {{access to private member outside any class}}
28
29 void (A::*a)(Public&) = &A::foo;
30 void (A::*b)(Protected&) = &A::foo; // expected-error {{access to protected member outside any class}}
31 void (A::*c)(Private&) = &A::foo; // expected-error {{access to private member outside any class}}
32 }
33}
John McCall5357b612010-01-28 01:42:12 +000034
35// Member operators.
36namespace test1 {
37 class A {
38 public:
39 void operator+(Public&);
40 void operator[](Public&);
41 protected:
42 void operator+(Protected&); // expected-note {{declared protected here}}
43 void operator[](Protected&); // expected-note {{declared protected here}}
44 private:
45 void operator+(Private&); // expected-note {{declared private here}}
46 void operator[](Private&); // expected-note {{declared private here}}
47 void operator-(); // expected-note {{declared private here}}
48 };
49 void operator+(const A &, Public&);
50 void operator+(const A &, Protected&);
51 void operator+(const A &, Private&);
52 void operator-(const A &);
53
54 void test(A &a, Public &pub, Protected &prot, Private &priv) {
55 a + pub;
56 a + prot; // expected-error {{access to protected member}}
57 a + priv; // expected-error {{access to private member}}
58 a[pub];
59 a[prot]; // expected-error {{access to protected member}}
60 a[priv]; // expected-error {{access to private member}}
61 -a; // expected-error {{access to private member}}
62
63 const A &ca = a;
64 ca + pub;
65 ca + prot;
66 ca + priv;
67 -ca;
68 }
69}