summaryrefslogtreecommitdiff
path: root/clang/test/CXX/class.access/class.access.base
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX/class.access/class.access.base')
-rw-r--r--clang/test/CXX/class.access/class.access.base/p1.cpp155
-rw-r--r--clang/test/CXX/class.access/class.access.base/p5.cpp75
2 files changed, 230 insertions, 0 deletions
diff --git a/clang/test/CXX/class.access/class.access.base/p1.cpp b/clang/test/CXX/class.access/class.access.base/p1.cpp
new file mode 100644
index 0000000..43cc99e
--- /dev/null
+++ b/clang/test/CXX/class.access/class.access.base/p1.cpp
@@ -0,0 +1,155 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// C++0x [class.access.base]p1(a):
+// If a class is declared to be a base class for another class using
+// the public access specifier, the public members of the base class
+// are accessible as public members of the derived class and protected
+// members of the base class are accessible as protected members of
+// the derived class.
+namespace test0 {
+ class Base {
+ public: int pub; static int spub;
+ protected: int prot; static int sprot; // expected-note 4 {{declared protected here}}
+ private: int priv; static int spriv; // expected-note 8 {{declared private here}}
+ };
+
+ class Test : public Base {
+ void test() {
+ pub++;
+ spub++;
+ prot++;
+ sprot++;
+ priv++; // expected-error {{private member}}
+ spriv++; // expected-error {{private member}}
+
+ Base::pub++;
+ Base::spub++;
+ Base::prot++;
+ Base::sprot++;
+ Base::priv++; // expected-error {{private member}}
+ Base::spriv++; // expected-error {{private member}}
+ }
+ };
+
+ void test(Test *t) {
+ t->pub++;
+ t->spub++;
+ t->prot++; // expected-error {{protected member}}
+ t->sprot++; // expected-error {{protected member}}
+ t->priv++; // expected-error {{private member}}
+ t->spriv++; // expected-error {{private member}}
+
+ t->Base::pub++;
+ t->Base::spub++;
+ t->Base::prot++; // expected-error {{protected member}}
+ t->Base::sprot++; // expected-error {{protected member}}
+ t->Base::priv++; // expected-error {{private member}}
+ t->Base::spriv++; // expected-error {{private member}}
+ }
+}
+
+// C++0x [class.access.base]p1(b):
+// If a class is declared to be a base class for another class using
+// the protected access specifier, the public and protected members
+// of the base class are accessible as protected members of the
+// derived class.
+namespace test1 {
+ class Base { // expected-note 6{{member is declared here}}
+ public:
+ int pub; // expected-note{{member is declared here}}
+ static int spub; // expected-note{{member is declared here}}
+ protected: int prot; static int sprot; // expected-note 4 {{declared protected here}}
+ private: int priv; static int spriv; // expected-note 8 {{declared private here}}
+ };
+
+ class Test : protected Base { // expected-note 6 {{declared protected here}} expected-note 8 {{constrained by protected inheritance here}}
+ void test() {
+ pub++;
+ spub++;
+ prot++;
+ sprot++;
+ priv++; // expected-error {{private member}}
+ spriv++; // expected-error {{private member}}
+
+ Base::pub++;
+ Base::spub++;
+ Base::prot++;
+ Base::sprot++;
+ Base::priv++; // expected-error {{private member}}
+ Base::spriv++; // expected-error {{private member}}
+ }
+ };
+
+ void test(Test *t) {
+ t->pub++; // expected-error {{protected member}} expected-error {{protected base class}}
+ t->spub++; // expected-error {{protected member}}
+ t->prot++; // expected-error {{protected member}} expected-error {{protected base class}}
+ t->sprot++; // expected-error {{protected member}}
+ t->priv++; // expected-error {{private member}} expected-error {{protected base class}}
+ t->spriv++; // expected-error {{private member}}
+
+ // Two possible errors here: one for Base, one for the member
+ t->Base::pub++; // expected-error {{protected member}} expected-error {{protected base class}}
+ t->Base::spub++; // expected-error {{protected member}}
+ t->Base::prot++; // expected-error 2 {{protected member}} expected-error {{protected base class}}
+ t->Base::sprot++; // expected-error 2 {{protected member}}
+ t->Base::priv++; // expected-error {{protected member}} expected-error {{private member}} expected-error {{protected base class}}
+ t->Base::spriv++; // expected-error {{protected member}} expected-error {{private member}}
+ }
+}
+
+// C++0x [class.access.base]p1(b):
+// If a class is declared to be a base class for another class using
+// the private access specifier, the public and protected members of
+// the base class are accessible as private members of the derived
+// class.
+namespace test2 {
+ class Base { // expected-note 6{{member is declared here}}
+ public:
+ int pub; // expected-note{{member is declared here}}
+ static int spub; // expected-note{{member is declared here}}
+ protected:
+ int prot; // expected-note {{declared protected here}} \
+ // expected-note{{member is declared here}}
+ static int sprot; // expected-note {{declared protected here}} \
+ // expected-note{{member is declared here}}
+ private:
+ int priv; // expected-note 4 {{declared private here}}
+ static int spriv; // expected-note 4 {{declared private here}}
+ };
+
+ class Test : private Base { // expected-note 6 {{declared private here}} \
+ // expected-note 10 {{constrained by private inheritance here}}
+ void test() {
+ pub++;
+ spub++;
+ prot++;
+ sprot++;
+ priv++; // expected-error {{private member}}
+ spriv++; // expected-error {{private member}}
+
+ Base::pub++;
+ Base::spub++;
+ Base::prot++;
+ Base::sprot++;
+ Base::priv++; // expected-error {{private member}}
+ Base::spriv++; // expected-error {{private member}}
+ }
+ };
+
+ void test(Test *t) {
+ t->pub++; // expected-error {{private member}} expected-error {{private base class}}
+ t->spub++; // expected-error {{private member}}
+ t->prot++; // expected-error {{private member}} expected-error {{private base class}}
+ t->sprot++; // expected-error {{private member}}
+ t->priv++; // expected-error {{private member}} expected-error {{private base class}}
+ t->spriv++; // expected-error {{private member}}
+
+ t->Base::pub++; // expected-error {{private member}} expected-error {{private base class}}
+ t->Base::spub++; // expected-error {{private member}}
+ t->Base::prot++; // expected-error {{protected member}} expected-error {{private member}} expected-error {{private base class}}
+ t->Base::sprot++; // expected-error {{protected member}} expected-error {{private member}}
+ t->Base::priv++; // expected-error 2 {{private member}} expected-error {{private base class}}
+ t->Base::spriv++; // expected-error 2 {{private member}}
+ }
+}
diff --git a/clang/test/CXX/class.access/class.access.base/p5.cpp b/clang/test/CXX/class.access/class.access.base/p5.cpp
new file mode 100644
index 0000000..255fbfc
--- /dev/null
+++ b/clang/test/CXX/class.access/class.access.base/p5.cpp
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -verify %s
+
+namespace test0 {
+ struct A {
+ static int x;
+ };
+ struct B : A {};
+ struct C : B {};
+
+ int test() {
+ return A::x
+ + B::x
+ + C::x;
+ }
+}
+
+namespace test1 {
+ struct A {
+ private: static int x; // expected-note 5 {{declared private here}}
+ static int test() { return x; }
+ };
+ struct B : public A {
+ static int test() { return x; } // expected-error {{private member}}
+ };
+ struct C : private A {
+ static int test() { return x; } // expected-error {{private member}}
+ };
+
+ struct D {
+ public: static int x; // expected-note{{member is declared here}}
+ static int test() { return x; }
+ };
+ struct E : private D { // expected-note{{constrained by private inheritance}}
+ static int test() { return x; }
+ };
+
+ int test() {
+ return A::x // expected-error {{private member}}
+ + B::x // expected-error {{private member}}
+ + C::x // expected-error {{private member}}
+ + D::x
+ + E::x; // expected-error {{private member}}
+ }
+}
+
+namespace test2 {
+ class A {
+ protected: static int x; // expected-note{{member is declared here}}
+ };
+
+ class B : private A {}; // expected-note {{private inheritance}}
+ class C : private A {
+ int test(B *b) {
+ return b->x; // expected-error {{private member}}
+ }
+ };
+}
+
+namespace test3 {
+ class A {
+ protected: static int x;
+ };
+
+ class B : public A {};
+ class C : private A {
+ int test(B *b) {
+ // x is accessible at C when named in A.
+ // A is an accessible base of B at C.
+ // Therefore this succeeds.
+ return b->x;
+ }
+ };
+}
+
+// TODO: flesh out these cases