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