blob: 09884316f9cd5186aba7e522600c70da75d61ce4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// 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 {
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 : 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 {
public:
int pub;
static int spub;
protected:
int prot; // expected-note {{declared protected here}}
static int sprot; // expected-note {{declared protected 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}}
}
}
|