2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2009-05-12 06:55:49 +08:00
|
|
|
|
|
|
|
friend class A; // expected-error {{'friend' used outside of class}}
|
|
|
|
void f() { friend class A; } // expected-error {{'friend' used outside of class}}
|
|
|
|
class C { friend class A; };
|
|
|
|
class D { void f() { friend class A; } }; // expected-error {{'friend' used outside of class}}
|
2009-12-12 04:04:54 +08:00
|
|
|
|
|
|
|
// PR5760
|
|
|
|
namespace test0 {
|
|
|
|
namespace ns {
|
|
|
|
void f(int);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
friend void ns::f(int a);
|
|
|
|
};
|
|
|
|
}
|
2009-12-18 07:21:11 +08:00
|
|
|
|
|
|
|
// Test derived from LLVM's Registry.h
|
|
|
|
namespace test1 {
|
|
|
|
template <class T> struct Outer {
|
|
|
|
void foo(T);
|
|
|
|
struct Inner {
|
|
|
|
friend void Outer::foo(T);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
(void) Outer<int>::Inner();
|
|
|
|
}
|
|
|
|
}
|
2009-12-23 08:44:38 +08:00
|
|
|
|
|
|
|
// PR5476
|
|
|
|
namespace test2 {
|
|
|
|
namespace foo {
|
|
|
|
void Func(int x);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar {
|
|
|
|
friend void ::test2::foo::Func(int x);
|
|
|
|
};
|
|
|
|
}
|
2009-12-23 09:09:14 +08:00
|
|
|
|
|
|
|
// PR5134
|
|
|
|
namespace test3 {
|
|
|
|
class Foo {
|
2010-07-14 14:36:18 +08:00
|
|
|
friend const int getInt(int inInt = 0);
|
2010-07-13 16:18:22 +08:00
|
|
|
|
2009-12-23 09:09:14 +08:00
|
|
|
};
|
|
|
|
}
|
2010-06-09 05:27:36 +08:00
|
|
|
|
|
|
|
namespace test4 {
|
|
|
|
class T4A {
|
|
|
|
friend class T4B;
|
|
|
|
|
|
|
|
public:
|
|
|
|
T4A(class T4B *);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T4B *mB; // error here
|
|
|
|
};
|
|
|
|
|
|
|
|
class T4B {};
|
|
|
|
}
|
2010-10-09 12:39:54 +08:00
|
|
|
|
|
|
|
namespace rdar8529993 {
|
2011-03-05 06:45:55 +08:00
|
|
|
struct A { ~A(); };
|
2010-10-09 12:39:54 +08:00
|
|
|
|
|
|
|
struct B : A
|
|
|
|
{
|
2011-03-05 06:45:55 +08:00
|
|
|
template<int> friend A::~A(); // expected-error {{destructor cannot be declared as a template}}
|
2010-10-09 12:39:54 +08:00
|
|
|
};
|
|
|
|
}
|
2010-11-10 11:01:53 +08:00
|
|
|
|
|
|
|
// PR7915
|
|
|
|
namespace test5 {
|
|
|
|
struct A;
|
|
|
|
struct A1 { friend void A(); };
|
|
|
|
|
|
|
|
struct B { friend void B(); };
|
|
|
|
}
|
2010-11-30 02:19:25 +08:00
|
|
|
|
|
|
|
// PR8479
|
|
|
|
namespace test6_1 {
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
private:
|
|
|
|
friend class vectorA;
|
|
|
|
A() {}
|
|
|
|
};
|
|
|
|
class vectorA {
|
|
|
|
public:
|
|
|
|
vectorA(int i, const A& t = A()) {}
|
|
|
|
};
|
|
|
|
void f() {
|
|
|
|
vectorA v(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace test6_2 {
|
|
|
|
template<class T>
|
|
|
|
class vector {
|
|
|
|
public:
|
|
|
|
vector(int i, const T& t = T()) {}
|
|
|
|
};
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
private:
|
|
|
|
friend class vector<A>;
|
|
|
|
A() {}
|
|
|
|
};
|
|
|
|
void f() {
|
|
|
|
vector<A> v(1);
|
|
|
|
}
|
|
|
|
}
|
2010-11-30 12:44:33 +08:00
|
|
|
namespace test6_3 {
|
|
|
|
template<class T>
|
|
|
|
class vector {
|
|
|
|
public:
|
|
|
|
vector(int i) {}
|
|
|
|
void f(const T& t = T()) {}
|
|
|
|
};
|
|
|
|
class A {
|
|
|
|
public:
|
|
|
|
private:
|
|
|
|
friend void vector<A>::f(const A&);
|
|
|
|
A() {}
|
|
|
|
};
|
|
|
|
void f() {
|
|
|
|
vector<A> v(1);
|
|
|
|
v.f();
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 03:51:19 +08:00
|
|
|
|
|
|
|
namespace test7 {
|
|
|
|
extern "C" {
|
|
|
|
class X {
|
|
|
|
friend int f() { return 42; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2013-04-04 05:19:47 +08:00
|
|
|
|
|
|
|
// PR15485
|
|
|
|
namespace test8 {
|
|
|
|
namespace ns1 {
|
|
|
|
namespace ns2 {
|
|
|
|
template<class T> void f(T t); // expected-note {{target of using declaration}}
|
|
|
|
}
|
|
|
|
using ns2::f; // expected-note {{using declaration}}
|
|
|
|
}
|
|
|
|
struct A { void f(); }; // expected-note {{target of using declaration}}
|
|
|
|
struct B : public A { using A::f; }; // expected-note {{using declaration}}
|
|
|
|
struct X {
|
|
|
|
template<class T> friend void ns1::f(T t); // expected-error {{cannot befriend target of using declaration}}
|
|
|
|
friend void B::f(); // expected-error {{cannot befriend target of using declaration}}
|
|
|
|
};
|
|
|
|
}
|