Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Anders Carlsson | 0033836 | 2009-05-11 22:55:49 +0000 | [diff] [blame] | 2 | |
| 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}} |
John McCall | e7e278b | 2009-12-11 20:04:54 +0000 | [diff] [blame] | 7 | |
| 8 | // PR5760 |
| 9 | namespace test0 { |
| 10 | namespace ns { |
| 11 | void f(int); |
| 12 | } |
| 13 | |
| 14 | struct A { |
| 15 | friend void ns::f(int a); |
| 16 | }; |
| 17 | } |
John McCall | e129d44 | 2009-12-17 23:21:11 +0000 | [diff] [blame] | 18 | |
| 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); |
| 25 | }; |
| 26 | }; |
| 27 | |
| 28 | void test() { |
| 29 | (void) Outer<int>::Inner(); |
| 30 | } |
| 31 | } |
John McCall | df37000 | 2009-12-23 00:44:38 +0000 | [diff] [blame] | 32 | |
| 33 | // PR5476 |
| 34 | namespace 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 McCall | bc12044 | 2009-12-23 01:09:14 +0000 | [diff] [blame] | 43 | |
| 44 | // PR5134 |
| 45 | namespace test3 { |
| 46 | class Foo { |
Douglas Gregor | de80ec1 | 2010-07-13 08:50:30 +0000 | [diff] [blame] | 47 | friend const int getInt(int inInt = 0); // expected-warning{{'const' type qualifier on return type has no effect}} |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 48 | |
John McCall | bc12044 | 2009-12-23 01:09:14 +0000 | [diff] [blame] | 49 | }; |
| 50 | } |
Douglas Gregor | e1aa9f3 | 2010-06-08 21:27:36 +0000 | [diff] [blame] | 51 | |
| 52 | namespace 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 | } |