Fix the clang-wpa example.
[clang.git] / test / SemaCXX / friend.cpp
blob1222dd0940da0f45f13a4827fc629b92b7f35e41
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 friend class A; // expected-error {{'friend' used outside of class}}
4 void f() { friend class A; } // expected-error {{'friend' used outside of class}}
5 class C { friend class A; };
6 class D { void f() { friend class A; } }; // expected-error {{'friend' used outside of class}}
8 // PR5760
9 namespace test0 {
10 namespace ns {
11 void f(int);
14 struct A {
15 friend void ns::f(int a);
19 // Test derived from LLVM's Registry.h
20 namespace test1 {
21 template <class T> struct Outer {
22 void foo(T);
23 struct Inner {
24 friend void Outer::foo(T);
28 void test() {
29 (void) Outer<int>::Inner();
33 // PR5476
34 namespace test2 {
35 namespace foo {
36 void Func(int x);
39 class Bar {
40 friend void ::test2::foo::Func(int x);
44 // PR5134
45 namespace test3 {
46 class Foo {
47 friend const int getInt(int inInt = 0);
52 namespace test4 {
53 class T4A {
54 friend class T4B;
56 public:
57 T4A(class T4B *);
59 protected:
60 T4B *mB; // error here
63 class T4B {};
66 namespace rdar8529993 {
67 struct A { ~A(); }; // expected-note {{nearly matches}}
69 struct B : A
71 template<int> friend A::~A(); // expected-error {{does not match}}
75 // PR7915
76 namespace test5 {
77 struct A;
78 struct A1 { friend void A(); };
80 struct B { friend void B(); };
83 // PR8479
84 namespace test6_1 {
85 class A {
86 public:
87 private:
88 friend class vectorA;
89 A() {}
91 class vectorA {
92 public:
93 vectorA(int i, const A& t = A()) {}
95 void f() {
96 vectorA v(1);
99 namespace test6_2 {
100 template<class T>
101 class vector {
102 public:
103 vector(int i, const T& t = T()) {}
105 class A {
106 public:
107 private:
108 friend class vector<A>;
109 A() {}
111 void f() {
112 vector<A> v(1);
115 namespace test6_3 {
116 template<class T>
117 class vector {
118 public:
119 vector(int i) {}
120 void f(const T& t = T()) {}
122 class A {
123 public:
124 private:
125 friend void vector<A>::f(const A&);
126 A() {}
128 void f() {
129 vector<A> v(1);
130 v.f();