| 1 |
// RUN: %clang_cc1 -std=c++11 -verify %s |
| 2 |
|
| 3 |
struct Public {} public_; |
| 4 |
struct Protected {} protected_; |
| 5 |
struct Private {} private_; |
| 6 |
|
| 7 |
class A { |
| 8 |
public: |
| 9 |
A(Public); |
| 10 |
void f(Public); |
| 11 |
|
| 12 |
protected: |
| 13 |
A(Protected); // expected-note {{protected here}} |
| 14 |
void f(Protected); |
| 15 |
|
| 16 |
private: |
| 17 |
A(Private); // expected-note 4{{private here}} |
| 18 |
void f(Private); // expected-note {{private here}} |
| 19 |
|
| 20 |
friend void Friend(); |
| 21 |
}; |
| 22 |
|
| 23 |
class B : private A { |
| 24 |
using A::A; // ok |
| 25 |
using A::f; // expected-error {{private member}} |
| 26 |
|
| 27 |
void f() { |
| 28 |
B a(public_); |
| 29 |
B b(protected_); |
| 30 |
B c(private_); // expected-error {{private}} |
| 31 |
} |
| 32 |
|
| 33 |
B(Public p, int) : B(p) {} |
| 34 |
B(Protected p, int) : B(p) {} |
| 35 |
B(Private p, int) : B(p) {} // expected-error {{private}} |
| 36 |
}; |
| 37 |
|
| 38 |
class C : public B { |
| 39 |
C(Public p) : B(p) {} |
| 40 |
// There is no access check on the conversion from derived to base here; |
| 41 |
// protected constructors of A act like protected constructors of B. |
| 42 |
C(Protected p) : B(p) {} |
| 43 |
C(Private p) : B(p) {} // expected-error {{private}} |
| 44 |
}; |
| 45 |
|
| 46 |
void Friend() { |
| 47 |
// There is no access check on the conversion from derived to base here. |
| 48 |
B a(public_); |
| 49 |
B b(protected_); |
| 50 |
B c(private_); |
| 51 |
} |
| 52 |
|
| 53 |
void NonFriend() { |
| 54 |
B a(public_); |
| 55 |
B b(protected_); // expected-error {{protected}} |
| 56 |
B c(private_); // expected-error {{private}} |
| 57 |
} |
| 58 |
|
| 59 |
namespace ProtectedAccessFromMember { |
| 60 |
namespace a { |
| 61 |
struct ES { |
| 62 |
private: |
| 63 |
ES(const ES &) = delete; |
| 64 |
protected: |
| 65 |
ES(const char *); |
| 66 |
}; |
| 67 |
} |
| 68 |
namespace b { |
| 69 |
struct DES : a::ES { |
| 70 |
DES *f(); |
| 71 |
private: |
| 72 |
using a::ES::ES; |
| 73 |
}; |
| 74 |
} |
| 75 |
b::DES *b::DES::f() { return new b::DES("foo"); } |
| 76 |
|
| 77 |
} |