1 // RUN: %clang_cc1 -fsyntax-only -verify %s
5 protected: int x
; // expected-note 3 {{declared}} \
6 // expected-note {{member is declared here}}
7 static int sx
; // expected-note 3 {{declared}} \
8 // expected-note {{member is declared here}}
12 class C
: protected A
{
14 class D
: private B
{ // expected-note 2 {{constrained}}
18 (void) a
.x
; // expected-error {{'x' is a protected member}}
19 (void) a
.sx
; // expected-error {{'sx' is a protected member}}
22 (void) b
.x
; // expected-error {{'x' is a protected member}}
23 (void) b
.sx
; // expected-error {{'sx' is a protected member}}
26 (void) c
.x
; // expected-error {{'x' is a protected member}}
27 (void) c
.sx
; // expected-error {{'sx' is a protected member}}
30 (void) d
.x
; // expected-error {{'x' is a private member}}
31 (void) d
.sx
; // expected-error {{'sx' is a private member}}
44 class C
: protected A
{
71 protected: int x
; // expected-note 3 {{can only access this member on an object of type}}
78 class C
: protected A
{
90 (void) a
.x
; // expected-error {{'x' is a protected member}}
94 (void) a
.x
; // expected-error {{'x' is a protected member}}
98 (void) a
.x
; // expected-error {{'x' is a protected member}}
106 protected: int x
; //expected-note {{declared protected}} // expected-note {{can only access this member on an object of type}}
108 static void test(B
&);
111 static void test(B
&);
113 class C
: protected A
{
114 static void test(B
&);
116 class D
: private B
{
117 static void test(B
&);
129 (void) b
.x
; // expected-error {{'x' is a protected member}}
133 (void) b
.x
; // expected-error {{'x' is a protected member}}
141 protected: int x
; // expected-note 2{{declared protected here}} expected-note{{member is declared here}}
142 static int sx
; // expected-note 3{{member is declared here}}
143 static void test(C
&);
146 static void test(C
&);
148 class C
: protected A
{ // expected-note 4 {{constrained}}
149 static void test(C
&);
151 class D
: private B
{
152 static void test(C
&);
156 (void) c
.x
; // expected-error {{'x' is a protected member}}
157 (void) c
.sx
; // expected-error {{'sx' is a protected member}}
160 (void) c
.x
; // expected-error {{'x' is a protected member}}
161 (void) c
.sx
; // expected-error {{'sx' is a protected member}}
168 (void) c
.x
; // expected-error {{'x' is a protected member}}
169 (void) c
.sx
; // expected-error {{'sx' is a protected member}}
176 protected: int x
; // expected-note 3{{member is declared here}}
177 static int sx
; // expected-note 3{{member is declared here}}
178 static void test(D
&);
181 static void test(D
&);
183 class C
: protected A
{
184 static void test(D
&);
186 class D
: private B
{ // expected-note 6 {{constrained}}
187 static void test(D
&);
191 (void) d
.x
; // expected-error {{'x' is a private member}}
192 (void) d
.sx
; // expected-error {{'sx' is a private member}}
195 (void) d
.x
; // expected-error {{'x' is a private member}}
196 (void) d
.sx
; // expected-error {{'sx' is a private member}}
199 (void) d
.x
; // expected-error {{'x' is a private member}}
200 (void) d
.sx
; // expected-error {{'sx' is a private member}}
212 void foo(int); // expected-note 3 {{can only access this member on an object of type}}
214 static void foo(Static
);
216 static void test(A
&);
219 static void test(A
&);
221 class C
: protected A
{
222 static void test(A
&);
224 class D
: private B
{
225 static void test(A
&);
233 a
.foo(10); // expected-error {{'foo' is a protected member}}
237 a
.foo(10); // expected-error {{'foo' is a protected member}}
241 a
.foo(10); // expected-error {{'foo' is a protected member}}
250 void foo(int); // expected-note 3 {{must name member using the type of the current context}}
252 static void foo(Static
);
259 class C
: protected A
{
262 class D
: private B
{
267 void (A::*x
)(int) = &A::foo
;
268 void (*sx
)(Static
) = &A::foo
;
271 void (A::*x
)(int) = &A::foo
; // expected-error {{'foo' is a protected member}}
272 void (*sx
)(Static
) = &A::foo
;
275 void (A::*x
)(int) = &A::foo
; // expected-error {{'foo' is a protected member}}
276 void (*sx
)(Static
) = &A::foo
;
279 void (A::*x
)(int) = &A::foo
; // expected-error {{'foo' is a protected member}}
280 void (*sx
)(Static
) = &A::foo
;
288 void foo(int); // expected-note 3 {{must name member using the type of the current context}}
290 static void foo(Static
);
297 class C
: protected A
{
300 class D
: private B
{
303 void call(void (A::*)(int));
304 void calls(void (*)(Static
));
311 call(&A::foo
); // expected-error {{'foo' is a protected member}}
315 call(&A::foo
); // expected-error {{'foo' is a protected member}}
319 call(&A::foo
); // expected-error {{'foo' is a protected member}}
325 class A
{ // expected-note {{member is declared here}}
326 protected: int foo(); // expected-note 4 {{declared}} expected-note 3 {{can only access this member on an object of type}} expected-note 2 {{member is declared here}}
329 class B
: public A
{ // expected-note {{member is declared here}}
333 class C
: protected B
{ // expected-note {{declared}} \
334 // expected-note 7 {{constrained}}
338 static void test(A
&a
) {
339 a
.foo(); // expected-error {{'foo' is a protected member}}
340 a
.A::foo(); // expected-error {{'foo' is a protected member}}
341 a
.B::foo(); // expected-error {{'foo' is a protected member}}
342 a
.C::foo(); // expected-error {{'foo' is a protected member}}
343 a
.D::foo(); // expected-error {{'foo' is a protected member}}
346 static void test(B
&b
) {
349 b
.B::foo(); // accessible as named in A
350 b
.C::foo(); // expected-error {{'foo' is a protected member}}
353 static void test(C
&c
) {
354 c
.foo(); // expected-error {{'foo' is a protected member}}
355 c
.A::foo(); // expected-error {{'A' is a protected member}} \
356 // expected-error {{cannot cast}}
357 c
.B::foo(); // expected-error {{'B' is a protected member}} \
358 // expected-error {{cannot cast}}
359 c
.C::foo(); // expected-error {{'foo' is a protected member}}
362 static void test(D
&d
) {
366 d
.C::foo(); // expected-error {{'foo' is a protected member}}
372 template<typename T
> class A
{
380 template class A
<int>;
383 // class.protected friendship
402 // This friendship is considered because a public member of A would be
403 // a private member of C.
405 class A
{ protected: int foo(); };
406 class B
: public virtual A
{};
407 class C
: private B
{ friend void test(); };
408 class D
: private C
, public virtual A
{};
416 // This friendship is not considered because a public member of A is
417 // inaccessible in C.
419 class A
{ protected: int foo(); }; // expected-note {{declared protected here}}
420 class B
: private virtual A
{};
421 class C
: private B
{ friend void test(); };
422 class D
: public virtual A
{};
426 d
.A::foo(); // expected-error {{protected member}}
434 template <class T
> void temp(T t
); // expected-note {{must name member using the type of the current context}}
436 void nontemp(int); // expected-note {{must name member using the type of the current context}}
438 template <class T
> void ovl_temp(T t
); // expected-note {{must name member using the type of the current context}}
439 void ovl_temp(float);
441 void ovl_nontemp(int); // expected-note {{must name member using the type of the current context}}
442 void ovl_nontemp(float);
444 template <class T
> void ovl_withtemp(T
);
445 void ovl_withtemp(int); // expected-note {{must name member using the type of the current context}}
451 ptr
= &A::temp
; // expected-error {{protected member}}
452 ptr
= &A::nontemp
; // expected-error {{protected member}}
453 ptr
= &A::ovl_temp
; // expected-error {{protected member}}
454 ptr
= &A::ovl_nontemp
; // expected-error {{protected member}}
455 ptr
= &A::ovl_withtemp
; // expected-error {{protected member}}
463 A(); // expected-note 2 {{protected constructor can only be used to construct a base class subobject}}
464 A(const A
&); // expected-note {{protected constructor can only be used to construct a base class subobject}}
465 ~A(); // expected-note 3 {{protected destructor can only be used to destroy a base class subobject}}
469 // The uses here are fine.
474 // All these uses are bad.
477 A a
; // expected-error {{protected constructor}} expected-error {{protected destructor}}
481 return new A(); // expected-error {{protected constructor}}
485 delete a
; // expected-error {{protected destructor}}
489 return *a
; // expected-error {{protected constructor}}
493 a
->~A(); // expected-error {{protected member}}
504 class B
: public virtual A
{