2009-08-06 10:15:43 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -verify %s
|
|
|
|
|
|
|
|
struct Outer {
|
|
|
|
struct Inner {
|
|
|
|
int intfield;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Base {
|
|
|
|
void base_member();
|
|
|
|
|
|
|
|
typedef int Int;
|
|
|
|
Int typedeffed_member();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Derived : public Base {
|
|
|
|
};
|
|
|
|
|
|
|
|
int myglobal;
|
|
|
|
|
2009-08-26 01:53:59 +08:00
|
|
|
void global_function();
|
|
|
|
extern "C" {
|
|
|
|
void global_c_function();
|
|
|
|
}
|
|
|
|
|
2009-08-06 10:15:43 +08:00
|
|
|
class A {
|
|
|
|
class AInner {
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class PreDeclared;
|
|
|
|
friend class Outer::Inner;
|
|
|
|
friend int Outer::Inner::intfield; // expected-error {{ friends can only be classes or functions }}
|
|
|
|
friend int Outer::Inner::missing_field; //expected-error {{ friends can only be classes or functions }}
|
|
|
|
friend int myoperation(float); // okay
|
|
|
|
friend int myglobal; // expected-error {{ friends can only be classes or functions }}
|
|
|
|
|
2009-08-26 01:53:59 +08:00
|
|
|
friend void global_function();
|
|
|
|
friend void global_c_function();
|
|
|
|
|
2009-08-28 15:59:38 +08:00
|
|
|
friend class UndeclaredSoFar;
|
|
|
|
UndeclaredSoFar x; // expected-error {{ unknown type name 'UndeclaredSoFar' }}
|
|
|
|
|
2009-08-06 10:15:43 +08:00
|
|
|
void a_member();
|
|
|
|
friend void A::a_member(); // expected-error {{ friends cannot be members of the declaring class }}
|
|
|
|
friend void a_member(); // okay (because we ignore class scopes when looking up friends)
|
2009-08-07 04:49:32 +08:00
|
|
|
friend class A::AInner; // this is okay as an extension
|
|
|
|
friend class AInner; // okay, refers to ::AInner
|
2009-08-06 10:15:43 +08:00
|
|
|
|
|
|
|
friend void Derived::missing_member(); // expected-error {{ no function named 'missing_member' with type 'void ()' was found in the specified scope }}
|
|
|
|
|
|
|
|
friend void Derived::base_member(); // expected-error {{ no function named 'base_member' with type 'void ()' was found in the specified scope }}
|
|
|
|
|
|
|
|
friend int Base::typedeffed_member(); // okay: should look through typedef
|
|
|
|
|
|
|
|
// These test that the friend is properly not being treated as a
|
|
|
|
// member function.
|
|
|
|
friend A operator|(const A& l, const A& r); // okay
|
|
|
|
friend A operator|(const A& r); // expected-error {{ overloaded 'operator|' must be a binary operator (has 1 parameter) }}
|
|
|
|
|
|
|
|
friend operator bool() const; // expected-error {{ must use a qualified name when declaring a conversion operator as a friend }}
|
|
|
|
|
|
|
|
typedef void ftypedef();
|
|
|
|
friend ftypedef typedeffed_function; // okay (because it's not declared as a member)
|
2009-09-02 10:15:17 +08:00
|
|
|
|
|
|
|
class facet;
|
|
|
|
friend class facet; // should not assert
|
|
|
|
class facet {};
|
2009-08-06 10:15:43 +08:00
|
|
|
};
|
|
|
|
|
2009-10-14 07:27:22 +08:00
|
|
|
A::UndeclaredSoFar y; // expected-error {{no type named 'UndeclaredSoFar' in 'class A'}}
|
2009-08-28 15:59:38 +08:00
|
|
|
|
2009-08-06 10:15:43 +08:00
|
|
|
class PreDeclared;
|
|
|
|
|
|
|
|
int myoperation(float f) {
|
|
|
|
return (int) f;
|
|
|
|
}
|