xref: /minix3/external/bsd/llvm/dist/clang/test/CXX/class.access/class.friend/p3-cxx0x.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2*f4a2713aSLionel Sambuc template<typename T>
3*f4a2713aSLionel Sambuc class X0 {
4*f4a2713aSLionel Sambuc   friend T;
5*f4a2713aSLionel Sambuc };
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc class Y1 { };
8*f4a2713aSLionel Sambuc enum E1 { };
9*f4a2713aSLionel Sambuc X0<Y1> x0a;
10*f4a2713aSLionel Sambuc X0<Y1 *> x0b;
11*f4a2713aSLionel Sambuc X0<int> x0c;
12*f4a2713aSLionel Sambuc X0<E1> x0d;
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc template<typename T>
15*f4a2713aSLionel Sambuc class X1 {
16*f4a2713aSLionel Sambuc   friend typename T::type; // expected-error{{no type named 'type' in 'Y1'}}
17*f4a2713aSLionel Sambuc };
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc struct Y2 {
20*f4a2713aSLionel Sambuc   struct type { };
21*f4a2713aSLionel Sambuc };
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc struct Y3 {
24*f4a2713aSLionel Sambuc   typedef int type;
25*f4a2713aSLionel Sambuc };
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc X1<Y2> x1a;
28*f4a2713aSLionel Sambuc X1<Y3> x1b;
29*f4a2713aSLionel Sambuc X1<Y1> x1c; // expected-note{{in instantiation of template class 'X1<Y1>' requested here}}
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc template<typename T> class B;
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc template<typename T>
34*f4a2713aSLionel Sambuc class A {
35*f4a2713aSLionel Sambuc   T x;
36*f4a2713aSLionel Sambuc public:
37*f4a2713aSLionel Sambuc   class foo {};
38*f4a2713aSLionel Sambuc   static int y;
39*f4a2713aSLionel Sambuc   template <typename S> friend class B<S>::ty; // expected-warning {{dependent nested name specifier 'B<S>::' for friend class declaration is not supported}}
40*f4a2713aSLionel Sambuc };
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc template<typename T> class B { typedef int ty; };
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc template<> class B<int> {
45*f4a2713aSLionel Sambuc   class ty {
f(A<int> & a)46*f4a2713aSLionel Sambuc     static int f(A<int> &a) { return a.y; } // ok, befriended
47*f4a2713aSLionel Sambuc   };
48*f4a2713aSLionel Sambuc };
f(A<char> & a)49*f4a2713aSLionel Sambuc int f(A<char> &a) { return a.y; } // FIXME: should be an error
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc struct {
52*f4a2713aSLionel Sambuc   // Ill-formed
53*f4a2713aSLionel Sambuc   int friend; // expected-error {{'friend' must appear first in a non-function declaration}}
54*f4a2713aSLionel Sambuc   unsigned friend int; // expected-error {{'friend' must appear first in a non-function declaration}}
55*f4a2713aSLionel Sambuc   const volatile friend int; // expected-error {{'friend' must appear first in a non-function declaration}}
56*f4a2713aSLionel Sambuc   int
57*f4a2713aSLionel Sambuc           friend; // expected-error {{'friend' must appear first in a non-function declaration}}
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc   // OK
60*f4a2713aSLionel Sambuc   int friend foo(void);
61*f4a2713aSLionel Sambuc   friend int;
62*f4a2713aSLionel Sambuc   friend const volatile int;
63*f4a2713aSLionel Sambuc       friend
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc   float;
66*f4a2713aSLionel Sambuc   template<typename T> friend class A<T>::foo; // expected-warning {{not supported}}
67*f4a2713aSLionel Sambuc } a;
68*f4a2713aSLionel Sambuc 
testA()69*f4a2713aSLionel Sambuc void testA() { (void)sizeof(A<int>); }
70