xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/cxx-friend.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc class C {
4f4a2713aSLionel Sambuc   friend class D;
5f4a2713aSLionel Sambuc };
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc class A {
8f4a2713aSLionel Sambuc public:
9f4a2713aSLionel Sambuc   void f();
10f4a2713aSLionel Sambuc };
11f4a2713aSLionel Sambuc 
12f4a2713aSLionel Sambuc friend int x; // expected-error {{'friend' used outside of class}}
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc friend class D {}; // expected-error {{'friend' used outside of class}}
15f4a2713aSLionel Sambuc 
16f4a2713aSLionel Sambuc union U {
17f4a2713aSLionel Sambuc   int u1;
18f4a2713aSLionel Sambuc };
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc class B {
21f4a2713aSLionel Sambuc   // 'A' here should refer to the declaration above.
22f4a2713aSLionel Sambuc   friend class A;
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc   friend C; // expected-warning {{specify 'class' to befriend}}
25f4a2713aSLionel Sambuc   friend U; // expected-warning {{specify 'union' to befriend}}
26f4a2713aSLionel Sambuc   friend int; // expected-warning {{non-class friend type 'int'}}
27f4a2713aSLionel Sambuc 
28f4a2713aSLionel Sambuc   friend void myfunc();
29f4a2713aSLionel Sambuc 
f(A * a)30f4a2713aSLionel Sambuc   void f(A *a) { a->f(); }
31f4a2713aSLionel Sambuc };
32f4a2713aSLionel Sambuc 
bar()33*0a6a1f1dSLionel Sambuc inline void bar() {} // expected-note {{previous definition is here}}
34f4a2713aSLionel Sambuc class E {
bar()35f4a2713aSLionel Sambuc   friend void bar() {} // expected-error {{redefinition of 'bar'}}
36f4a2713aSLionel Sambuc };
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc 
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc template <typename t1, typename t2> class some_template;
42f4a2713aSLionel Sambuc friend   // expected-error {{'friend' used outside of class}}
43f4a2713aSLionel Sambuc some_template<foo, bar>&  // expected-error {{use of undeclared identifier 'foo'}}
44f4a2713aSLionel Sambuc   ;  // expected-error {{expected unqualified-id}}
45