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