blob: 05289b10d26cabb95a0b843e5d77331277cc5baa [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
3// PR5057
John McCall4b6e90a2009-12-11 20:51:23 +00004namespace test0 {
5 namespace std {
6 class X {
7 public:
8 template<typename T> friend struct Y;
9 };
10 }
11
12 namespace std {
13 template<typename T> struct Y {};
14 }
Douglas Gregord85bea22009-09-26 06:47:28 +000015}
16
John McCall4b6e90a2009-12-11 20:51:23 +000017namespace test1 {
Douglas Gregor182ddf02009-09-28 00:08:27 +000018 template<typename T> void f1(T) { } // expected-note{{here}}
19
20 class X {
21 template<typename T> friend void f0(T);
22 template<typename T> friend void f1(T);
23 };
24
25 template<typename T> void f0(T) { }
26 template<typename T> void f1(T) { } // expected-error{{redefinition}}
27}
Douglas Gregord7e5bdb2009-10-09 21:11:42 +000028
29// PR4768
John McCall4b6e90a2009-12-11 20:51:23 +000030namespace test2 {
31 template<typename T> struct X0 {
32 template<typename U> friend struct X0;
33 };
34
35 template<typename T> struct X0<T*> {
36 template<typename U> friend struct X0;
37 };
Douglas Gregord7e5bdb2009-10-09 21:11:42 +000038
John McCall4b6e90a2009-12-11 20:51:23 +000039 template<> struct X0<int> {
40 template<typename U> friend struct X0;
41 };
Douglas Gregord7e5bdb2009-10-09 21:11:42 +000042
John McCall4b6e90a2009-12-11 20:51:23 +000043 template<typename T> struct X1 {
44 template<typename U> friend void f2(U);
45 template<typename U> friend void f3(U);
46 };
Douglas Gregora735b202009-10-13 14:39:41 +000047
John McCall4b6e90a2009-12-11 20:51:23 +000048 template<typename U> void f2(U);
Douglas Gregora735b202009-10-13 14:39:41 +000049
John McCall4b6e90a2009-12-11 20:51:23 +000050 X1<int> x1i;
51 X0<int*> x0ip;
Douglas Gregora735b202009-10-13 14:39:41 +000052
John McCall4b6e90a2009-12-11 20:51:23 +000053 template<> void f2(int);
Douglas Gregora735b202009-10-13 14:39:41 +000054
John McCall4b6e90a2009-12-11 20:51:23 +000055 // FIXME: Should this declaration of f3 be required for the specialization of
56 // f3<int> (further below) to work? GCC and EDG don't require it, we do...
57 template<typename U> void f3(U);
Douglas Gregora735b202009-10-13 14:39:41 +000058
John McCall4b6e90a2009-12-11 20:51:23 +000059 template<> void f3(int);
60}
Douglas Gregore8c01bd2009-10-30 21:07:27 +000061
62// PR5332
John McCall4b6e90a2009-12-11 20:51:23 +000063namespace test3 {
64 template <typename T> class Foo {
65 template <typename U>
66 friend class Foo;
67 };
Douglas Gregore8c01bd2009-10-30 21:07:27 +000068
John McCall4b6e90a2009-12-11 20:51:23 +000069 Foo<int> foo;
Douglas Gregor259571e2009-10-30 22:42:42 +000070
John McCall4b6e90a2009-12-11 20:51:23 +000071 template<typename T, T Value> struct X2a;
Douglas Gregor259571e2009-10-30 22:42:42 +000072
John McCall4b6e90a2009-12-11 20:51:23 +000073 template<typename T, int Size> struct X2b;
Douglas Gregor259571e2009-10-30 22:42:42 +000074
John McCall4b6e90a2009-12-11 20:51:23 +000075 template<typename T>
76 class X3 {
77 template<typename U, U Value> friend struct X2a;
78 template<typename U, T Value> friend struct X2b;
79 };
Douglas Gregor259571e2009-10-30 22:42:42 +000080
John McCall4b6e90a2009-12-11 20:51:23 +000081 X3<int> x3i; // okay
Douglas Gregor259571e2009-10-30 22:42:42 +000082
John McCall4b6e90a2009-12-11 20:51:23 +000083 X3<long> x3l; // FIXME: should cause an instantiation-time failure
84}
John McCalle976ffe2009-12-14 23:19:40 +000085
86// PR5716
87namespace test4 {
88 template<typename> struct A {
89 template<typename T> friend void f(const A<T>&);
90 };
91
92 template<typename T> void f(const A<T>&) {
93 int a[sizeof(T) ? -1 : -1]; // expected-error {{array size is negative}}
94 }
95
96 void f() {
97 f(A<int>()); // expected-note {{in instantiation of function template specialization}}
98 }
99}
John McCall65c49462009-12-18 11:25:59 +0000100
101namespace test5 {
102 class outer {
103 class foo;
104 template <typename T> friend struct cache;
105 };
106 class outer::foo {
107 template <typename T> friend struct cache;
108 };
109}