Home | History | Annotate | Download | only in class.friend
      1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
      2 template<typename T>
      3 class X0 {
      4   friend T;
      5 };
      6 
      7 class Y1 { };
      8 enum E1 { };
      9 X0<Y1> x0a;
     10 X0<Y1 *> x0b;
     11 X0<int> x0c;
     12 X0<E1> x0d;
     13 
     14 template<typename T>
     15 class X1 {
     16   friend typename T::type; // expected-error{{no type named 'type' in 'Y1'}}
     17 };
     18 
     19 struct Y2 {
     20   struct type { };
     21 };
     22 
     23 struct Y3 {
     24   typedef int type;
     25 };
     26 
     27 X1<Y2> x1a;
     28 X1<Y3> x1b;
     29 X1<Y1> x1c; // expected-note{{in instantiation of template class 'X1<Y1>' requested here}}
     30 
     31 template<typename T> class B;
     32 
     33 template<typename T>
     34 class A {
     35   T x;
     36 public:
     37   class foo {};
     38   static int y;
     39   template <typename S> friend class B<S>::ty;
     40 };
     41 
     42 template <typename T> class B { typedef int ty; };
     43 
     44 struct {
     45   // Ill-formed
     46   int friend; // expected-error {{'friend' must appear first in a non-function declaration}}
     47   unsigned friend int; // expected-error {{'friend' must appear first in a non-function declaration}}
     48   const volatile friend int; // expected-error {{'friend' must appear first in a non-function declaration}}
     49   int
     50           friend; // expected-error {{'friend' must appear first in a non-function declaration}}
     51 
     52   // OK
     53   int friend foo(void);
     54   friend int;
     55   friend const volatile int;
     56       friend
     57 
     58   float;
     59   template<typename T> friend class A<T>::foo;
     60 } a;
     61 
     62 void testA() { (void)sizeof(A<int>); }
     63