19ca5c425SRichard Smith // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s 23b4abb67SDouglas Gregor template<typename T> 33b4abb67SDouglas Gregor class X0 { 43b4abb67SDouglas Gregor friend T; 53b4abb67SDouglas Gregor }; 63b4abb67SDouglas Gregor 73b4abb67SDouglas Gregor class Y1 { }; 83b4abb67SDouglas Gregor enum E1 { }; 93b4abb67SDouglas Gregor X0<Y1> x0a; 103b4abb67SDouglas Gregor X0<Y1 *> x0b; 113b4abb67SDouglas Gregor X0<int> x0c; 123b4abb67SDouglas Gregor X0<E1> x0d; 133b4abb67SDouglas Gregor 143b4abb67SDouglas Gregor template<typename T> 153b4abb67SDouglas Gregor class X1 { 163b4abb67SDouglas Gregor friend typename T::type; // expected-error{{no type named 'type' in 'Y1'}} 173b4abb67SDouglas Gregor }; 183b4abb67SDouglas Gregor 193b4abb67SDouglas Gregor struct Y2 { 203b4abb67SDouglas Gregor struct type { }; 213b4abb67SDouglas Gregor }; 223b4abb67SDouglas Gregor 233b4abb67SDouglas Gregor struct Y3 { 243b4abb67SDouglas Gregor typedef int type; 253b4abb67SDouglas Gregor }; 263b4abb67SDouglas Gregor 273b4abb67SDouglas Gregor X1<Y2> x1a; 283b4abb67SDouglas Gregor X1<Y3> x1b; 293b4abb67SDouglas Gregor X1<Y1> x1c; // expected-note{{in instantiation of template class 'X1<Y1>' requested here}} 30a31a89a3SRichard Smith 3136722d26SNick Lewycky template<typename T> class B; 3236722d26SNick Lewycky 33a31a89a3SRichard Smith template<typename T> 34a31a89a3SRichard Smith class A { 35a31a89a3SRichard Smith T x; 36a31a89a3SRichard Smith public: 37a31a89a3SRichard Smith class foo {}; 38a31a89a3SRichard Smith static int y; 39cd556eb2SRichard Smith template <typename S> friend class B<S>::ty; // expected-warning {{dependent nested name specifier 'B<S>::' for friend class declaration is not supported}} 40a31a89a3SRichard Smith }; 41a31a89a3SRichard Smith 4236722d26SNick Lewycky template<typename T> class B { typedef int ty; }; 4336722d26SNick Lewycky 44cd556eb2SRichard Smith template<> class B<int> { 45cd556eb2SRichard Smith class ty { f(A<int> & a)46cd556eb2SRichard Smith static int f(A<int> &a) { return a.y; } // ok, befriended 47cd556eb2SRichard Smith }; 48cd556eb2SRichard Smith }; f(A<char> & a)49cd556eb2SRichard Smithint f(A<char> &a) { return a.y; } // FIXME: should be an error 50cd556eb2SRichard Smith 51a31a89a3SRichard Smith struct { 52a31a89a3SRichard Smith // Ill-formed 53a31a89a3SRichard Smith int friend; // expected-error {{'friend' must appear first in a non-function declaration}} 54a31a89a3SRichard Smith unsigned friend int; // expected-error {{'friend' must appear first in a non-function declaration}} 55*7499610eSEli Friedman const volatile friend int; // expected-error {{'friend' must appear first in a non-function declaration}} \ 56*7499610eSEli Friedman // expected-error {{'const' is invalid in friend declarations}} \ 57*7499610eSEli Friedman // expected-error {{'volatile' is invalid in friend declarations}} 58a31a89a3SRichard Smith int 59a31a89a3SRichard Smith friend; // expected-error {{'friend' must appear first in a non-function declaration}} 60*7499610eSEli Friedman friend const int; // expected-error {{'const' is invalid in friend declarations}} 61*7499610eSEli Friedman friend volatile int; // expected-error {{'volatile' is invalid in friend declarations}} 62*7499610eSEli Friedman template <typename T> friend const class X; // expected-error {{'const' is invalid in friend declarations}} 63*7499610eSEli Friedman // C++ doesn't have restrict and _Atomic, but they're both the same sort 64*7499610eSEli Friedman // of qualifier. 65*7499610eSEli Friedman typedef int *PtrToInt; 66*7499610eSEli Friedman friend __restrict PtrToInt; // expected-error {{'restrict' is invalid in friend declarations}} \ 67*7499610eSEli Friedman // expected-error {{restrict requires a pointer or reference}} 68*7499610eSEli Friedman friend _Atomic int; // expected-error {{'_Atomic' is invalid in friend declarations}} 69a31a89a3SRichard Smith 70a31a89a3SRichard Smith // OK 71a31a89a3SRichard Smith int friend foo(void); 72*7499610eSEli Friedman const int friend foo2(void); 73a31a89a3SRichard Smith friend int; 74a31a89a3SRichard Smith friend 75a31a89a3SRichard Smith 76a31a89a3SRichard Smith float; 77cd556eb2SRichard Smith template<typename T> friend class A<T>::foo; // expected-warning {{not supported}} 78a31a89a3SRichard Smith } a; 7936722d26SNick Lewycky testA()8036722d26SNick Lewyckyvoid testA() { (void)sizeof(A<int>); } 81