| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 4 |
|
| 5 |
class C { |
| 6 |
friend class D; |
| 7 |
}; |
| 8 |
|
| 9 |
class A { |
| 10 |
public: |
| 11 |
void f(); |
| 12 |
}; |
| 13 |
|
| 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 |
|
| 22 |
class B { |
| 23 |
// 'A' here should refer to the declaration above. |
| 24 |
friend class A; |
| 25 |
|
| 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 |
| 40 |
|
| 41 |
friend void myfunc(); |
| 42 |
|
| 43 |
void f(A *a) { a->f(); } |
| 44 |
}; |
| 45 |
|
| 46 |
inline void bar() {} // expected-note {{previous definition is here}} |
| 47 |
class E { |
| 48 |
friend void bar() {} // expected-error {{redefinition of 'bar'}} |
| 49 |
}; |
| 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}} |