78 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -verify %s2 3struct Public {} public_;4struct Protected {} protected_;5struct Private {} private_;6 7class A {8public:9 A(Public);10 void f(Public);11 12protected:13 A(Protected); // expected-note {{protected here}}14 void f(Protected);15 16private:17 A(Private); // expected-note 4{{private here}}18 void f(Private); // expected-note {{private here}}19 20 friend void Friend();21};22 23class B : private A {24 using A::A; // ok25 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 38class 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 46void 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 53void NonFriend() {54 B a(public_);55 B b(protected_); // expected-error {{protected}}56 B c(private_); // expected-error {{private}}57}58 59namespace ProtectedAccessFromMember {60namespace a {61 struct ES {62 private:63 ES(const ES &) = delete;64 protected:65 ES(const char *);66 };67}68namespace b {69 struct DES : a::ES {70 DES *f();71 private:72 using a::ES::ES;73 };74}75b::DES *b::DES::f() { return new b::DES("foo"); }76 77}78