1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 // C++0x [class.access]p6:
4 // All access controls in [class.access] affect the ability to
5 // access a class member name from a particular scope. For purposes
6 // of access control, the base-specifiers of a class and the
7 // definitions of class members that appear outside of the class
8 // definition are considered to be within the scope of that
9 // class. In particular, access controls apply as usual to member
10 // names accessed as part of a function return type, even though it
11 // is not possible to determine the access privileges of that use
12 // without first parsing the rest of the function
13 // declarator. Similarly, access control for implicit calls to the
14 // constructors, the conversion functions, or the destructor called
15 // to create and destroy a static data member is performed as if
16 // these calls appeared in the scope of the member's class.
18 struct Public
{}; struct Protected
{}; struct Private
{};
22 typedef int type
; // expected-note {{declared private here}}
26 A::type
foo() { } // expected-error {{'type' is a private member}}
38 operator Protected (); // expected-note {{declared protected here}}
39 A(Protected
); // expected-note {{declared protected here}}
41 operator Private (); // expected-note {{declared private here}}
42 A(Private
); // expected-note {{declared private here}}
48 Protected prot
= a
; // expected-error {{'operator Protected' is a protected member}}
49 Private priv
= a
; // expected-error {{'operator Private' is a private member}}
51 A aprot
= prot
; // expected-error {{protected constructor}}
52 A apriv
= priv
; // expected-error {{private constructor}}
60 template <class T
> static void set(T
&t
, typename
T::type v
) {
63 template <class T
> static typename
T::type
get(const T
&t
) {
84 class Green
{}; class Blue
{};
86 // We have to wrap this in a class because a partial specialization
87 // isn't actually in the context of the template.
89 template <class T
, class Nat
> class A
{
93 template <class T
> class Outer::A
<T
, typename
T::nature
> {
95 static void foo(); // expected-note {{'Outer::A<B, Green>::foo' declared here}}
99 private: typedef Green nature
;
104 Outer::A
<B
, Green
>::foo();
105 Outer::A
<B
, Blue
>::foo(); // expected-error {{no member named 'foo' in 'test3::Outer::A<test3::B, test3::Blue>'; did you mean 'Outer::A<B, Green>::foo'?}}
110 template <class T
> class A
{
111 private: typedef int type
;
112 template <class U
> friend void foo(U
&, typename
U::type
);
115 template <class U
> void foo(U
&, typename
U::type
) {}
126 enum Enum
{ E0
, E1
, E2
}; // expected-note 4 {{declared private here}}
127 template <Enum
> void foo();
128 template <Enum
> class bar
;
131 template <A::Enum en
> void A::foo() {}
132 template <A::Enum en
> class A::bar
{};
134 template <A::Enum en
> void foo() {} // expected-error {{'Enum' is a private member of 'test5::A'}}
135 template <A::Enum en
> class bar
{}; // expected-error {{'Enum' is a private member of 'test5::A'}}
138 template <A::Enum en
> void foo() {} // expected-error {{'Enum' is a private member of 'test5::A'}}
139 template <A::Enum en
> class bar
{}; // expected-error {{'Enum' is a private member of 'test5::A'}}
145 public: class public_inner
{};
146 protected: class protected_inner
{};
147 private: class private_inner
{}; // expected-note {{declared private here}}
153 private_inner c
; // expected-error {{'private_inner' is a private member of 'test6::A'}}
159 void foo(int arg
[1]);
168 void foo(int arg
[__builtin_offsetof(B
, ins
)]);
174 typedef void* (A::*UnspecifiedBoolType
)() const;
175 operator UnspecifiedBoolType() const; // expected-note {{implicitly declared private here}}
179 if (a
) return; // expected-error-re {{'operator void *(test8::A::*)(){{( __attribute__\(\(thiscall\)\))?}} const' is a private member of 'test8::A'}}
185 operator char*() const; // expected-note {{implicitly declared private here}}
189 delete a
; // expected-error {{'operator char *' is a private member of 'test9::A'}}