1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 // C++98 [class.friend]p7:
4 // C++11 [class.friend]p9:
5 // A name nominated by a friend declaration shall be accessible in
6 // the scope of the class containing the friend declaration.
9 // Simple, non-templated case.
12 void f(); // expected-note {{implicitly declared private here}}
16 friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test0::X'}}
20 // Templated but non-dependent.
23 void f(); // expected-note {{implicitly declared private here}}
26 template <class T
> class Y
{
27 friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test1::X'}}
31 // Dependent but instantiated at the right type.
33 template <class T
> class Y
;
40 template <class T
> class Y
{
44 template class Y
<int>;
47 // Dependent and instantiated at the wrong type.
49 template <class T
> class Y
;
52 void f(); // expected-note {{implicitly declared private here}}
56 template <class T
> class Y
{
57 friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test3::X'}}
60 template class Y
<float>; // expected-note {{in instantiation}}
63 // Dependent because dependently-scoped.
65 template <class T
> class X
{
69 template <class T
> class Y
{
70 friend void X
<T
>::f();
74 // Dependently-scoped, no friends.
76 template <class T
> class X
{
77 void f(); // expected-note {{implicitly declared private here}}
80 template <class T
> class Y
{
81 friend void X
<T
>::f(); // expected-error {{friend function 'f' is a private member of 'test5::X<int>'}}
84 template class Y
<int>; // expected-note {{in instantiation}}
87 // Dependently-scoped, wrong friend.
89 template <class T
> class Y
;
91 template <class T
> class X
{
92 void f(); // expected-note {{implicitly declared private here}}
93 friend class Y
<float>;
96 template <class T
> class Y
{
97 friend void X
<T
>::f(); // expected-error {{friend function 'f' is a private member of 'test6::X<int>'}}
100 template class Y
<int>; // expected-note {{in instantiation}}
103 // Dependently-scoped, right friend.
105 template <class T
> class Y
;
107 template <class T
> class X
{
112 template <class T
> class Y
{
113 friend void X
<T
>::f();
116 template class Y
<int>;