1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc struct Outer { 4*f4a2713aSLionel Sambuc struct Inner { 5*f4a2713aSLionel Sambuc int intfield; 6*f4a2713aSLionel Sambuc }; 7*f4a2713aSLionel Sambuc }; 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc struct Base { 10*f4a2713aSLionel Sambuc void base_member(); 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambuc typedef int Int; 13*f4a2713aSLionel Sambuc Int typedeffed_member(); 14*f4a2713aSLionel Sambuc }; 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc struct Derived : public Base { 17*f4a2713aSLionel Sambuc }; 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc int myglobal; 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc void global_function(); 22*f4a2713aSLionel Sambuc extern "C" { 23*f4a2713aSLionel Sambuc void global_c_function(); 24*f4a2713aSLionel Sambuc } 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc class A { 27*f4a2713aSLionel Sambuc class AInner { 28*f4a2713aSLionel Sambuc }; 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc friend class PreDeclared; 31*f4a2713aSLionel Sambuc friend class Outer::Inner; 32*f4a2713aSLionel Sambuc friend int Outer::Inner::intfield; // expected-error {{friends can only be classes or functions}} 33*f4a2713aSLionel Sambuc friend int Outer::Inner::missing_field; //expected-error {{friends can only be classes or functions}} 34*f4a2713aSLionel Sambuc friend int myoperation(float); // okay 35*f4a2713aSLionel Sambuc friend int myglobal; // expected-error {{friends can only be classes or functions}} 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc friend void global_function(); 38*f4a2713aSLionel Sambuc friend void global_c_function(); 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc friend class UndeclaredSoFar; 41*f4a2713aSLionel Sambuc UndeclaredSoFar x; // expected-error {{unknown type name 'UndeclaredSoFar'}} 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc void a_member(); 44*f4a2713aSLionel Sambuc friend void A::a_member(); // expected-error {{friends cannot be members of the declaring class}} 45*f4a2713aSLionel Sambuc friend void a_member(); // okay (because we ignore class scopes when looking up friends) 46*f4a2713aSLionel Sambuc friend class A::AInner; // this is okay as an extension 47*f4a2713aSLionel Sambuc friend class AInner; // okay, refers to ::AInner 48*f4a2713aSLionel Sambuc 49*f4a2713aSLionel Sambuc friend void Derived::missing_member(); // expected-error {{no function named 'missing_member' with type 'void ()' was found in the specified scope}} 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc friend void Derived::base_member(); // expected-error {{no function named 'base_member' with type 'void ()' was found in the specified scope}} 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc friend int Base::typedeffed_member(); // okay: should look through typedef 54*f4a2713aSLionel Sambuc 55*f4a2713aSLionel Sambuc // These test that the friend is properly not being treated as a 56*f4a2713aSLionel Sambuc // member function. 57*f4a2713aSLionel Sambuc friend A operator|(const A& l, const A& r); // okay 58*f4a2713aSLionel Sambuc friend A operator|(const A& r); // expected-error {{overloaded 'operator|' must be a binary operator (has 1 parameter)}} 59*f4a2713aSLionel Sambuc 60*f4a2713aSLionel Sambuc friend operator bool() const; // expected-error {{must use a qualified name when declaring a conversion operator as a friend}} \ 61*f4a2713aSLionel Sambuc // expected-error{{non-member function cannot have 'const' qualifier}} 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc typedef void ftypedef(); 64*f4a2713aSLionel Sambuc friend ftypedef typedeffed_function; // okay (because it's not declared as a member) 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambuc class facet; 67*f4a2713aSLionel Sambuc friend class facet; // should not assert 68*f4a2713aSLionel Sambuc class facet {}; 69*f4a2713aSLionel Sambuc }; 70*f4a2713aSLionel Sambuc 71*f4a2713aSLionel Sambuc A::UndeclaredSoFar y; // expected-error {{no type named 'UndeclaredSoFar' in 'A'}} 72*f4a2713aSLionel Sambuc 73*f4a2713aSLionel Sambuc class PreDeclared; 74*f4a2713aSLionel Sambuc myoperation(float f)75*f4a2713aSLionel Sambucint myoperation(float f) { 76*f4a2713aSLionel Sambuc return (int) f; 77*f4a2713aSLionel Sambuc } 78