2010-01-27 09:50:18 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s
|
|
|
|
|
|
|
|
// C++0x [class.access]p4:
|
|
|
|
|
|
|
|
// Access control is applied uniformly to all names, whether the
|
|
|
|
// names are referred to from declarations or expressions. In the
|
|
|
|
// case of overloaded function names, access control is applied to
|
|
|
|
// the function selected by overload resolution.
|
|
|
|
|
|
|
|
class Public {} PublicInst;
|
|
|
|
class Protected {} ProtectedInst;
|
|
|
|
class Private {} PrivateInst;
|
|
|
|
|
|
|
|
namespace test0 {
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
void foo(Public&);
|
|
|
|
protected:
|
|
|
|
void foo(Protected&); // expected-note 2 {{declared protected here}}
|
|
|
|
private:
|
|
|
|
void foo(Private&); // expected-note 2 {{declared private here}}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test(A *op) {
|
|
|
|
op->foo(PublicInst);
|
2010-02-10 17:31:12 +08:00
|
|
|
op->foo(ProtectedInst); // expected-error {{'foo' is a protected member}}
|
|
|
|
op->foo(PrivateInst); // expected-error {{'foo' is a private member}}
|
2010-01-27 09:50:18 +08:00
|
|
|
|
|
|
|
void (A::*a)(Public&) = &A::foo;
|
2010-02-10 17:31:12 +08:00
|
|
|
void (A::*b)(Protected&) = &A::foo; // expected-error {{'foo' is a protected member}}
|
|
|
|
void (A::*c)(Private&) = &A::foo; // expected-error {{'foo' is a private member}}
|
2010-01-27 09:50:18 +08:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 09:42:12 +08:00
|
|
|
|
|
|
|
// Member operators.
|
|
|
|
namespace test1 {
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
void operator+(Public&);
|
|
|
|
void operator[](Public&);
|
2010-01-28 09:54:34 +08:00
|
|
|
void operator()(Public&);
|
2010-01-28 15:38:46 +08:00
|
|
|
typedef void (*PublicSurrogate)(Public&);
|
|
|
|
operator PublicSurrogate() const;
|
2010-01-28 09:42:12 +08:00
|
|
|
protected:
|
|
|
|
void operator+(Protected&); // expected-note {{declared protected here}}
|
|
|
|
void operator[](Protected&); // expected-note {{declared protected here}}
|
2010-01-28 09:54:34 +08:00
|
|
|
void operator()(Protected&); // expected-note {{declared protected here}}
|
2010-01-28 15:38:46 +08:00
|
|
|
typedef void (*ProtectedSurrogate)(Protected&);
|
|
|
|
operator ProtectedSurrogate() const; // expected-note {{declared protected here}}
|
2010-01-28 09:42:12 +08:00
|
|
|
private:
|
|
|
|
void operator+(Private&); // expected-note {{declared private here}}
|
|
|
|
void operator[](Private&); // expected-note {{declared private here}}
|
2010-01-28 09:54:34 +08:00
|
|
|
void operator()(Private&); // expected-note {{declared private here}}
|
2010-01-28 09:42:12 +08:00
|
|
|
void operator-(); // expected-note {{declared private here}}
|
2010-01-28 15:38:46 +08:00
|
|
|
typedef void (*PrivateSurrogate)(Private&);
|
|
|
|
operator PrivateSurrogate() const; // expected-note {{declared private here}}
|
2010-01-28 09:42:12 +08:00
|
|
|
};
|
|
|
|
void operator+(const A &, Public&);
|
|
|
|
void operator+(const A &, Protected&);
|
|
|
|
void operator+(const A &, Private&);
|
|
|
|
void operator-(const A &);
|
|
|
|
|
|
|
|
void test(A &a, Public &pub, Protected &prot, Private &priv) {
|
|
|
|
a + pub;
|
2010-02-10 17:31:12 +08:00
|
|
|
a + prot; // expected-error {{'operator+' is a protected member}}
|
|
|
|
a + priv; // expected-error {{'operator+' is a private member}}
|
2010-01-28 09:42:12 +08:00
|
|
|
a[pub];
|
2010-02-10 17:31:12 +08:00
|
|
|
a[prot]; // expected-error {{'operator[]' is a protected member}}
|
|
|
|
a[priv]; // expected-error {{'operator[]' is a private member}}
|
2010-01-28 09:54:34 +08:00
|
|
|
a(pub);
|
2010-02-10 17:31:12 +08:00
|
|
|
a(prot); // expected-error {{'operator()' is a protected member}}
|
|
|
|
a(priv); // expected-error {{'operator()' is a private member}}
|
|
|
|
-a; // expected-error {{'operator-' is a private member}}
|
2010-01-28 09:42:12 +08:00
|
|
|
|
|
|
|
const A &ca = a;
|
|
|
|
ca + pub;
|
|
|
|
ca + prot;
|
|
|
|
ca + priv;
|
|
|
|
-ca;
|
2010-01-28 15:38:46 +08:00
|
|
|
// These are all surrogate calls
|
|
|
|
ca(pub);
|
2010-02-10 17:31:12 +08:00
|
|
|
ca(prot); // expected-error {{'operator void (*)(class Protected &)' is a protected member}}
|
|
|
|
ca(priv); // expected-error {{'operator void (*)(class Private &)' is a private member}}
|
2010-01-28 09:42:12 +08:00
|
|
|
}
|
|
|
|
}
|
2010-02-02 16:45:54 +08:00
|
|
|
|
|
|
|
// Implicit constructor calls.
|
|
|
|
namespace test2 {
|
|
|
|
class A {
|
|
|
|
private:
|
|
|
|
A(); // expected-note {{declared private here}}
|
|
|
|
|
|
|
|
static A foo;
|
|
|
|
};
|
|
|
|
|
2010-02-10 17:31:12 +08:00
|
|
|
A a; // expected-error {{calling a private constructor}}
|
2010-02-02 16:45:54 +08:00
|
|
|
A A::foo; // okay
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implicit destructor calls.
|
|
|
|
namespace test3 {
|
|
|
|
class A{
|
|
|
|
private:
|
|
|
|
~A(); // expected-note 3 {{declared private here}}
|
|
|
|
static A foo;
|
|
|
|
};
|
|
|
|
|
2010-02-10 17:31:12 +08:00
|
|
|
A a; // expected-error {{'~A' is a private member}}
|
2010-02-02 16:45:54 +08:00
|
|
|
A A::foo;
|
|
|
|
|
2010-02-10 17:31:12 +08:00
|
|
|
void foo(A param) { // expected-error {{'~A' is a private member}}
|
|
|
|
A local; // expected-error {{'~A' is a private member}}
|
2010-02-02 16:45:54 +08:00
|
|
|
}
|
|
|
|
}
|