blob: 8bc2631e119f31d217ef55a8a470278e6a69f34b [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;
77 template<typename U, T Value> friend struct X2b;
78 };
Douglas Gregor259571e2009-10-30 22:42:42 +000079
John McCall4b6e90a2009-12-11 20:51:23 +000080 X3<int> x3i; // okay
Douglas Gregor259571e2009-10-30 22:42:42 +000081
John McCall4b6e90a2009-12-11 20:51:23 +000082 X3<long> x3l; // FIXME: should cause an instantiation-time failure
83}
John McCalle976ffe2009-12-14 23:19:40 +000084
85// PR5716
86namespace test4 {
87 template<typename> struct A {
88 template<typename T> friend void f(const A<T>&);
89 };
90
91 template<typename T> void f(const A<T>&) {
92 int a[sizeof(T) ? -1 : -1]; // expected-error {{array size is negative}}
93 }
94
95 void f() {
96 f(A<int>()); // expected-note {{in instantiation of function template specialization}}
97 }
98}
John McCall65c49462009-12-18 11:25:59 +000099
100namespace test5 {
101 class outer {
102 class foo;
103 template <typename T> friend struct cache;
104 };
105 class outer::foo {
106 template <typename T> friend struct cache;
107 };
108}
Douglas Gregor5d52e472010-01-16 18:09:52 +0000109
110// PR6022
111namespace PR6022 {
112 template <class T1, class T2 , class T3 > class A;
113
114 namespace inner {
115 template<class T1, class T2, class T3, class T>
116 A<T1, T2, T3>& f0(A<T1, T2, T3>&, T);
117 }
118
119 template<class T1, class T2, class T3>
120 class A {
121 template<class U1, class U2, class U3, class T>
122 friend A<U1, U2, U3>& inner::f0(A<U1, U2, U3>&, T);
123 };
124}
125