Clang Project

clang_source_code/test/Parser/cxx-friend.cpp
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
5class C {
6  friend class D;
7};
8
9class A {
10public:
11  void f();
12};
13
14friend int x; // expected-error {{'friend' used outside of class}}
15
16friend class D {}; // expected-error {{'friend' used outside of class}}
17
18union U {
19  int u1;
20};
21
22class 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
46inline void bar() {} // expected-note {{previous definition is here}}
47class E {
48  friend void bar() {} // expected-error {{redefinition of 'bar'}}
49};
50
51
52
53
54template <typename t1, typename t2> class some_template;
55friend   // expected-error {{'friend' used outside of class}}
56some_template<foo, bar>&  // expected-error {{use of undeclared identifier 'foo'}}
57  ;  // expected-error {{expected unqualified-id}}
58