blob: 6ee30aa7775a5733e5b5216667dd7ac93b689014 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregord85bea22009-09-26 06:47:28 +00002// PR5057
John McCall4b6e90a2009-12-11 20:51:23 +00003namespace test0 {
4 namespace std {
5 class X {
6 public:
7 template<typename T> friend struct Y;
8 };
9 }
10
11 namespace std {
12 template<typename T> struct Y {};
13 }
Douglas Gregord85bea22009-09-26 06:47:28 +000014}
15
John McCall4b6e90a2009-12-11 20:51:23 +000016namespace test1 {
Douglas Gregor182ddf02009-09-28 00:08:27 +000017 template<typename T> void f1(T) { } // expected-note{{here}}
18
19 class X {
20 template<typename T> friend void f0(T);
21 template<typename T> friend void f1(T);
22 };
23
24 template<typename T> void f0(T) { }
25 template<typename T> void f1(T) { } // expected-error{{redefinition}}
26}
Douglas Gregord7e5bdb2009-10-09 21:11:42 +000027
28// PR4768
John McCall4b6e90a2009-12-11 20:51:23 +000029namespace test2 {
30 template<typename T> struct X0 {
31 template<typename U> friend struct X0;
32 };
33
34 template<typename T> struct X0<T*> {
35 template<typename U> friend struct X0;
36 };
Douglas Gregord7e5bdb2009-10-09 21:11:42 +000037
John McCall4b6e90a2009-12-11 20:51:23 +000038 template<> struct X0<int> {
39 template<typename U> friend struct X0;
40 };
Douglas Gregord7e5bdb2009-10-09 21:11:42 +000041
John McCall4b6e90a2009-12-11 20:51:23 +000042 template<typename T> struct X1 {
43 template<typename U> friend void f2(U);
44 template<typename U> friend void f3(U);
45 };
Douglas Gregora735b202009-10-13 14:39:41 +000046
John McCall4b6e90a2009-12-11 20:51:23 +000047 template<typename U> void f2(U);
Douglas Gregora735b202009-10-13 14:39:41 +000048
John McCall4b6e90a2009-12-11 20:51:23 +000049 X1<int> x1i;
50 X0<int*> x0ip;
Douglas Gregora735b202009-10-13 14:39:41 +000051
John McCall4b6e90a2009-12-11 20:51:23 +000052 template<> void f2(int);
Douglas Gregora735b202009-10-13 14:39:41 +000053
John McCall4b6e90a2009-12-11 20:51:23 +000054 // 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);
Douglas Gregora735b202009-10-13 14:39:41 +000057
John McCall4b6e90a2009-12-11 20:51:23 +000058 template<> void f3(int);
59}
Douglas Gregore8c01bd2009-10-30 21:07:27 +000060
61// PR5332
John McCall4b6e90a2009-12-11 20:51:23 +000062namespace test3 {
63 template <typename T> class Foo {
64 template <typename U>
65 friend class Foo;
66 };
Douglas Gregore8c01bd2009-10-30 21:07:27 +000067
John McCall4b6e90a2009-12-11 20:51:23 +000068 Foo<int> foo;
Douglas Gregor259571e2009-10-30 22:42:42 +000069
John McCall4b6e90a2009-12-11 20:51:23 +000070 template<typename T, T Value> struct X2a;
Douglas Gregor259571e2009-10-30 22:42:42 +000071
John McCall4b6e90a2009-12-11 20:51:23 +000072 template<typename T, int Size> struct X2b;
Douglas Gregor259571e2009-10-30 22:42:42 +000073
John McCall4b6e90a2009-12-11 20:51:23 +000074 template<typename T>
75 class X3 {
76 template<typename U, U Value> friend struct X2a;
John McCall93ba8572010-03-25 06:39:04 +000077
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}}
John McCall4b6e90a2009-12-11 20:51:23 +000082 };
Douglas Gregor259571e2009-10-30 22:42:42 +000083
John McCall4b6e90a2009-12-11 20:51:23 +000084 X3<int> x3i; // okay
Douglas Gregor259571e2009-10-30 22:42:42 +000085
John McCall93ba8572010-03-25 06:39:04 +000086 X3<long> x3l; // expected-note {{in instantiation}}
John McCall4b6e90a2009-12-11 20:51:23 +000087}
John McCalle976ffe2009-12-14 23:19:40 +000088
89// PR5716
90namespace test4 {
91 template<typename> struct A {
92 template<typename T> friend void f(const A<T>&);
93 };
94
95 template<typename T> void f(const A<T>&) {
96 int a[sizeof(T) ? -1 : -1]; // expected-error {{array size is negative}}
97 }
98
99 void f() {
100 f(A<int>()); // expected-note {{in instantiation of function template specialization}}
101 }
102}
John McCall65c49462009-12-18 11:25:59 +0000103
104namespace test5 {
105 class outer {
106 class foo;
107 template <typename T> friend struct cache;
108 };
109 class outer::foo {
110 template <typename T> friend struct cache;
111 };
112}
Douglas Gregor5d52e472010-01-16 18:09:52 +0000113
114// PR6022
115namespace PR6022 {
116 template <class T1, class T2 , class T3 > class A;
117
118 namespace inner {
119 template<class T1, class T2, class T3, class T>
120 A<T1, T2, T3>& f0(A<T1, T2, T3>&, T);
121 }
122
123 template<class T1, class T2, class T3>
124 class A {
125 template<class U1, class U2, class U3, class T>
126 friend A<U1, U2, U3>& inner::f0(A<U1, U2, U3>&, T);
127 };
128}
129