Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Anders Carlsson | cd8db41 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 4 | |
| 5 | class C { |
| 6 | friend class D; |
| 7 | }; |
Anders Carlsson | 22e3784 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 8 | |
| 9 | class A { |
| 10 | public: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11 | void f(); |
Anders Carlsson | 22e3784 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 12 | }; |
| 13 | |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 14 | friend int x; // expected-error {{'friend' used outside of class}} |
| 15 | |
| 16 | friend class D {}; // expected-error {{'friend' used outside of class}} |
| 17 | |
| 18 | union U { |
| 19 | int u1; |
| 20 | }; |
| 21 | |
Anders Carlsson | 22e3784 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 22 | class B { |
| 23 | // 'A' here should refer to the declaration above. |
| 24 | friend class A; |
| 25 | |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame] | 26 | friend C; |
| 27 | #if __cplusplus <= 199711L |
| 28 | // expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'class' to befriend 'C'}} |
| 29 | #endif |
| 30 | |
| 31 | friend U; |
| 32 | #if __cplusplus <= 199711L |
| 33 | // expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'union' to befriend 'U'}} |
| 34 | #endif |
| 35 | |
| 36 | friend int; |
| 37 | #if __cplusplus <= 199711L |
| 38 | // expected-warning@-2 {{non-class friend type 'int' is a C++11 extension}} |
| 39 | #endif |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 40 | |
| 41 | friend void myfunc(); |
| 42 | |
| 43 | void f(A *a) { a->f(); } |
Anders Carlsson | 22e3784 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 44 | }; |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 45 | |
David Majnemer | ee4f402 | 2014-03-30 06:44:54 +0000 | [diff] [blame] | 46 | inline void bar() {} // expected-note {{previous definition is here}} |
Alp Toker | 19bff32 | 2013-10-18 05:54:24 +0000 | [diff] [blame] | 47 | class E { |
| 48 | friend void bar() {} // expected-error {{redefinition of 'bar'}} |
| 49 | }; |
Chris Lattner | 045cbff | 2009-12-07 00:48:47 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | template <typename t1, typename t2> class some_template; |
| 55 | friend // expected-error {{'friend' used outside of class}} |
| 56 | some_template<foo, bar>& // expected-error {{use of undeclared identifier 'foo'}} |
| 57 | ; // expected-error {{expected unqualified-id}} |