Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 2 | |
| 3 | class C { |
| 4 | friend class D; |
| 5 | }; |
Anders Carlsson | 5dc2af1 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 6 | |
| 7 | class A { |
| 8 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9 | void f(); |
Anders Carlsson | 5dc2af1 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 12 | friend int x; // expected-error {{'friend' used outside of class}} |
| 13 | |
| 14 | friend class D {}; // expected-error {{'friend' used outside of class}} |
| 15 | |
| 16 | union U { |
| 17 | int u1; |
| 18 | }; |
| 19 | |
Anders Carlsson | 5dc2af1 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 20 | class B { |
| 21 | // 'A' here should refer to the declaration above. |
| 22 | friend class A; |
| 23 | |
Douglas Gregor | 06245bf | 2010-04-07 17:57:12 +0000 | [diff] [blame] | 24 | friend C; // expected-warning {{must specify 'class' to befriend}} |
| 25 | friend U; // expected-warning {{must specify 'union' to befriend}} |
| 26 | friend int; // expected-warning {{non-class type 'int' cannot be a friend}} |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 27 | |
| 28 | friend void myfunc(); |
| 29 | |
| 30 | void f(A *a) { a->f(); } |
Anders Carlsson | 5dc2af1 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 31 | }; |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 32 | |
Chris Lattner | bd87c0b | 2009-12-07 00:48:47 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | template <typename t1, typename t2> class some_template; |
| 38 | friend // expected-error {{'friend' used outside of class}} |
| 39 | some_template<foo, bar>& // expected-error {{use of undeclared identifier 'foo'}} |
| 40 | ; // expected-error {{expected unqualified-id}} |