// RUN: %clang_cc1 -fsyntax-only -verify %s // C++98 [class.friend]p7: // C++11 [class.friend]p9: // A name nominated by a friend declaration shall be accessible in // the scope of the class containing the friend declaration. // PR12328 // Simple, non-templated case. namespace test0 { class X { void f(); // expected-note {{implicitly declared private here}} }; class Y { friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test0::X'}} }; } // Templated but non-dependent. namespace test1 { class X { void f(); // expected-note {{implicitly declared private here}} }; template class Y { friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test1::X'}} }; } // Dependent but instantiated at the right type. namespace test2 { template class Y; class X { void f(); friend class Y; }; template class Y { friend void X::f(); }; template class Y; } // Dependent and instantiated at the wrong type. namespace test3 { template class Y; class X { void f(); // expected-note {{implicitly declared private here}} friend class Y; }; template class Y { friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test3::X'}} }; template class Y; // expected-note {{in instantiation}} } // Dependent because dependently-scoped. namespace test4 { template class X { void f(); }; template class Y { friend void X::f(); }; } // Dependently-scoped, no friends. namespace test5 { template class X { void f(); // expected-note {{implicitly declared private here}} }; template class Y { friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test5::X'}} }; template class Y; // expected-note {{in instantiation}} } // Dependently-scoped, wrong friend. namespace test6 { template class Y; template class X { void f(); // expected-note {{implicitly declared private here}} friend class Y; }; template class Y { friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test6::X'}} }; template class Y; // expected-note {{in instantiation}} } // Dependently-scoped, right friend. namespace test7 { template class Y; template class X { void f(); friend class Y; }; template class Y { friend void X::f(); }; template class Y; }