diff options
Diffstat (limited to 'test/CXX/class.access')
-rw-r--r-- | test/CXX/class.access/class.protected/p1.cpp | 69 | ||||
-rw-r--r-- | test/CXX/class.access/p4.cpp | 25 | ||||
-rw-r--r-- | test/CXX/class.access/p6.cpp | 20 |
3 files changed, 101 insertions, 13 deletions
diff --git a/test/CXX/class.access/class.protected/p1.cpp b/test/CXX/class.access/class.protected/p1.cpp index 778e16a..8698fb1 100644 --- a/test/CXX/class.access/class.protected/p1.cpp +++ b/test/CXX/class.access/class.protected/p1.cpp @@ -68,7 +68,7 @@ namespace test1 { namespace test2 { class A { - protected: int x; // expected-note 3 {{declared}} + protected: int x; // expected-note 3 {{object type must derive}} static int sx; static void test(A&); }; @@ -103,7 +103,7 @@ namespace test2 { namespace test3 { class B; class A { - protected: int x; // expected-note {{declared}} + protected: int x; // expected-note {{object type must derive}} static int sx; static void test(B&); }; @@ -138,7 +138,7 @@ namespace test3 { namespace test4 { class C; class A { - protected: int x; // expected-note 3 {{declared}} + protected: int x; // expected-note {{declared}} expected-note 2 {{object type must derive}} static int sx; // expected-note 3{{member is declared here}} static void test(C&); }; @@ -215,7 +215,7 @@ namespace test6 { class Static {}; class A { protected: - void foo(int); // expected-note 3 {{declared}} + void foo(int); // expected-note 3 {{object type must derive}} void foo(long); static void foo(Static); @@ -253,7 +253,7 @@ namespace test7 { class Static {}; class A { protected: - void foo(int); // expected-note 3 {{declared}} + void foo(int); // expected-note 3 {{object type must derive}} void foo(long); static void foo(Static); @@ -291,7 +291,7 @@ namespace test8 { class Static {}; class A { protected: - void foo(int); // expected-note 3 {{declared}} + void foo(int); // expected-note 3 {{object type must derive}} void foo(long); static void foo(Static); @@ -329,8 +329,7 @@ namespace test8 { namespace test9 { class A { // expected-note {{member is declared here}} - protected: int foo(); // expected-note 8 {{declared}} \ - // expected-note {{member is declared here}} + protected: int foo(); // expected-note 4 {{declared}} expected-note 2 {{object type must derive}} expected-note {{object type 'test9::A' must derive}} }; class B : public A { // expected-note {{member is declared here}} @@ -338,7 +337,7 @@ namespace test9 { }; class C : protected B { // expected-note {{declared}} \ - // expected-note 6 {{constrained}} + // expected-note 9 {{constrained}} }; class D : public A { @@ -351,7 +350,7 @@ namespace test9 { static void test(B &b) { b.foo(); - b.A::foo(); // expected-error {{'foo' is a protected member}} + b.A::foo(); b.B::foo(); b.C::foo(); // expected-error {{'foo' is a protected member}} } @@ -359,8 +358,7 @@ namespace test9 { static void test(C &c) { c.foo(); // expected-error {{'foo' is a protected member}} \ // expected-error {{cannot cast}} - c.A::foo(); // expected-error {{'foo' is a protected member}} \ - // expected-error {{'A' is a protected member}} \ + c.A::foo(); // expected-error {{'A' is a protected member}} \ // expected-error {{cannot cast}} c.B::foo(); // expected-error {{'B' is a protected member}} \ // expected-error {{cannot cast}} @@ -388,3 +386,50 @@ namespace test10 { template class A<int>; } + +// rdar://problem/8360285: class.protected friendship +namespace test11 { + class A { + protected: + int foo(); + }; + + class B : public A { + friend class C; + }; + + class C { + void test() { + B b; + b.A::foo(); + } + }; +} + +// This friendship is considered because a public member of A would be +// a private member of C. +namespace test12 { + class A { protected: int foo(); }; + class B : public virtual A {}; + class C : private B { friend void test(); }; + class D : private C, public virtual A {}; + + void test() { + D d; + d.A::foo(); + } +} + +// This friendship is not considered because a public member of A is +// inaccessible in C. +namespace test13 { + class A { protected: int foo(); }; // expected-note {{declared protected here}} + class B : private virtual A {}; + class C : private B { friend void test(); }; + class D : public virtual A {}; + + void test() { + D d; + d.A::foo(); // expected-error {{protected member}} + } +} diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index 90a1449..115a22a 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -372,7 +372,7 @@ namespace test15 { int private_foo; // expected-note {{declared private here}} static int private_sfoo; // expected-note {{declared private here}} protected: - int protected_foo; // expected-note 4 {{declared protected here}} + int protected_foo; // expected-note 3 {{declared protected here}} // expected-note {{object type must derive from context type 'test15::B<int>'}} static int protected_sfoo; // expected-note 3 {{declared protected here}} int test1(A<int> &a) { @@ -427,3 +427,26 @@ namespace test16 { void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}} \ // expected-error{{exception object of type 'test16::A' has private destructor}} } + +// rdar://problem/8146294 +namespace test17 { + class A { + template <typename T> class Inner { }; // expected-note {{declared private here}} + }; + + A::Inner<int> s; // expected-error {{'Inner' is a private member of 'test17::A'}} +} + +namespace test18 { + template <class T> class A {}; + class B : A<int> { + A<int> member; + }; + + // FIXME: this access to A should be forbidden (because C++ is dumb), + // but LookupResult can't express the necessary information to do + // the check, so we aggressively suppress access control. + class C : B { + A<int> member; + }; +} diff --git a/test/CXX/class.access/p6.cpp b/test/CXX/class.access/p6.cpp index 734a4d8..8795708 100644 --- a/test/CXX/class.access/p6.cpp +++ b/test/CXX/class.access/p6.cpp @@ -119,3 +119,23 @@ namespace test4 { foo(a, 0); } } + +// PR7644 +namespace test5 { + class A { + enum Enum { E0, E1, E2 }; // expected-note 4 {{declared private here}} + template <Enum> void foo(); + template <Enum> class bar; + }; + + template <A::Enum en> void A::foo() {} + template <A::Enum en> class A::bar {}; + + template <A::Enum en> void foo() {} // expected-error {{'Enum' is a private member of 'test5::A'}} + template <A::Enum en> class bar {}; // expected-error {{'Enum' is a private member of 'test5::A'}} + + class B { + template <A::Enum en> void foo() {} // expected-error {{'Enum' is a private member of 'test5::A'}} + template <A::Enum en> class bar {}; // expected-error {{'Enum' is a private member of 'test5::A'}} + }; +} |