blob: 939d3ae456879f3a62ee3ba09193b7015779f463 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Anders Carlsson38811702009-05-11 22:55:49 +00002
3friend class A; // expected-error {{'friend' used outside of class}}
4void f() { friend class A; } // expected-error {{'friend' used outside of class}}
5class C { friend class A; };
6class D { void f() { friend class A; } }; // expected-error {{'friend' used outside of class}}
John McCall2b058ef2009-12-11 20:04:54 +00007
8// PR5760
9namespace test0 {
10 namespace ns {
11 void f(int);
12 }
13
14 struct A {
15 friend void ns::f(int a);
16 };
17}
John McCall90d3bb92009-12-17 23:21:11 +000018
19// Test derived from LLVM's Registry.h
20namespace test1 {
21 template <class T> struct Outer {
22 void foo(T);
23 struct Inner {
24 friend void Outer::foo(T);
25 };
26 };
27
28 void test() {
29 (void) Outer<int>::Inner();
30 }
31}
John McCalldb3062c2009-12-23 00:44:38 +000032
33// PR5476
34namespace test2 {
35 namespace foo {
36 void Func(int x);
37 }
38
39 class Bar {
40 friend void ::test2::foo::Func(int x);
41 };
42}
John McCallb50c4432009-12-23 01:09:14 +000043
44// PR5134
45namespace test3 {
46 class Foo {
Chandler Carruthcb3b5a42010-07-14 06:36:18 +000047 friend const int getInt(int inInt = 0);
Douglas Gregor603d81b2010-07-13 08:18:22 +000048
John McCallb50c4432009-12-23 01:09:14 +000049 };
50}
Douglas Gregor6f2e0952010-06-08 21:27:36 +000051
52namespace test4 {
53 class T4A {
54 friend class T4B;
55
56 public:
57 T4A(class T4B *);
58
59 protected:
60 T4B *mB; // error here
61 };
62
63 class T4B {};
64}
Argyrios Kyrtzidis52da8da2010-10-09 04:39:54 +000065
66namespace rdar8529993 {
67struct A { ~A(); }; // expected-note {{nearly matches}}
68
69struct B : A
70{
71 template<int> friend A::~A(); // expected-error {{does not match}}
72};
73}
John McCalla8987a2942010-11-10 03:01:53 +000074
75// PR7915
76namespace test5 {
77 struct A;
78 struct A1 { friend void A(); };
79
80 struct B { friend void B(); };
81}