1 // RUN: %clang_cc1 -fsyntax-only -verify %s
7 template<typename T
> friend struct Y
;
12 template<typename T
> struct Y
{};
17 template<typename T
> void f1(T
) { } // expected-note{{here}}
20 template<typename T
> friend void f0(T
);
21 template<typename T
> friend void f1(T
);
24 template<typename T
> void f0(T
) { }
25 template<typename T
> void f1(T
) { } // expected-error{{redefinition}}
30 template<typename T
> struct X0
{
31 template<typename U
> friend struct X0
;
34 template<typename T
> struct X0
<T
*> {
35 template<typename U
> friend struct X0
;
38 template<> struct X0
<int> {
39 template<typename U
> friend struct X0
;
42 template<typename T
> struct X1
{
43 template<typename U
> friend void f2(U
);
44 template<typename U
> friend void f3(U
);
47 template<typename U
> void f2(U
);
52 template<> void f2(int);
54 // FIXME: Should this declaration of f3 be required for the specialization of
55 // f3<int> (further below) to work? GCC and EDG don't require it, we do...
56 template<typename U
> void f3(U
);
58 template<> void f3(int);
63 template <typename T
> class Foo
{
70 template<typename T
, T Value
> struct X2a
;
72 template<typename T
, int Size
> struct X2b
;
76 template<typename U
, U Value
> friend struct X2a
;
78 // FIXME: the redeclaration note ends up here because redeclaration
79 // lookup ends up finding the friend target from X3<int>.
80 template<typename U
, T Value
> friend struct X2b
; // expected-error {{template non-type parameter has a different type 'long' in template redeclaration}} \
81 // expected-note {{previous non-type template parameter with type 'int' is here}}
86 X3
<long> x3l
; // expected-note {{in instantiation}}
91 template<typename
> struct A
{
92 template<typename T
> friend void f(const A
<T
>&);
95 template<typename T
> void f(const A
<T
>&) {
96 int a
[sizeof(T
) ? -1 : -1]; // expected-error {{array with a negative size}}
100 f(A
<int>()); // expected-note {{in instantiation of function template specialization}}
107 template <typename T
> friend struct cache
;
110 template <typename T
> friend struct cache
;
116 template <class T1
, class T2
, class T3
> class A
;
119 template<class T1
, class T2
, class T3
, class T
>
120 A
<T1
, T2
, T3
>& f0(A
<T1
, T2
, T3
>&, T
);
123 template<class T1
, class T2
, class T3
>
125 template<class U1
, class U2
, class U3
, class T
>
126 friend A
<U1
, U2
, U3
>& inner::f0(A
<U1
, U2
, U3
>&, T
);
130 namespace FriendTemplateDefinition
{
131 template<unsigned > struct int_c
{ };
136 friend void f(X
, int_c
<N
>) {
141 void test_X(X
<int> x
, int_c
<5> i5
) {
147 template<class > struct X0
151 template<typename
> struct X1
154 template<typename
, typename T
> struct X2
160 template <typename
= int, typename
= X1
<int> > struct X3
162 template <typename T1
, typename T2
, typename B
> friend void op(X2
<T1
, T2
>& , B
);
164 template <typename Ch
, typename Tr
, typename B
> void op(X2
<Ch
, Tr
>& , B
)
171 X2
<int, X0
<int> > ngs
;
179 template<class > struct X0
183 template<typename
> struct X1
186 template<typename
, typename T
> struct X2
192 template <typename
= X1
<int> > struct X3
194 template <typename T1
, typename T2
, typename B
> friend void op(X2
<T1
, T2
>& , B
);
196 template <typename Ch
, typename Tr
, typename B
> void op(X2
<Ch
, Tr
>& , B
)
203 X2
<int, X0
<int> > ngs
;
212 template<typename T
, typename U
, unsigned N
>
214 template<unsigned M
> friend class X
<T
, U
, M
>; // expected-error{{partial specialization cannot be declared as a friend}}
220 // Don't crash, and error on invalid friend type template.
221 namespace friend_type_template_no_tag
{
222 template <typename T
> struct S
{
223 template <typename U
> friend S
<U
>; // expected-error{{friend type templates must use an elaborated type}}
225 template struct S
<int>;