Douglas Gregor | 182ddf0 | 2009-09-28 00:08:27 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 2 | |
| 3 | // PR5057 |
| 4 | namespace std { |
| 5 | class X { |
| 6 | public: |
| 7 | template<typename T> |
| 8 | friend struct Y; |
| 9 | }; |
| 10 | } |
| 11 | |
| 12 | namespace std { |
| 13 | template<typename T> |
| 14 | struct Y |
| 15 | { |
| 16 | }; |
| 17 | } |
Douglas Gregor | 182ddf0 | 2009-09-28 00:08:27 +0000 | [diff] [blame] | 18 | |
| 19 | |
| 20 | namespace N { |
| 21 | template<typename T> void f1(T) { } // expected-note{{here}} |
| 22 | |
| 23 | class X { |
| 24 | template<typename T> friend void f0(T); |
| 25 | template<typename T> friend void f1(T); |
| 26 | }; |
| 27 | |
| 28 | template<typename T> void f0(T) { } |
| 29 | template<typename T> void f1(T) { } // expected-error{{redefinition}} |
| 30 | } |
Douglas Gregor | d7e5bdb | 2009-10-09 21:11:42 +0000 | [diff] [blame] | 31 | |
| 32 | // PR4768 |
| 33 | template<typename T> |
| 34 | struct X0 { |
| 35 | template<typename U> friend struct X0; |
| 36 | }; |
| 37 | |
| 38 | template<typename T> |
| 39 | struct X0<T*> { |
| 40 | template<typename U> friend struct X0; |
| 41 | }; |
| 42 | |
| 43 | template<> |
| 44 | struct X0<int> { |
| 45 | template<typename U> friend struct X0; |
| 46 | }; |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 47 | |
| 48 | template<typename T> |
| 49 | struct X1 { |
| 50 | template<typename U> friend void f2(U); |
| 51 | template<typename U> friend void f3(U); |
| 52 | }; |
| 53 | |
| 54 | template<typename U> void f2(U); |
| 55 | |
| 56 | X1<int> x1i; |
Douglas Gregor | e8c01bd | 2009-10-30 21:07:27 +0000 | [diff] [blame] | 57 | X0<int*> x0ip; |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 58 | |
| 59 | template<> void f2(int); |
| 60 | |
| 61 | // FIXME: Should this declaration of f3 be required for the specialization of |
| 62 | // f3<int> (further below) to work? GCC and EDG don't require it, we do... |
| 63 | template<typename U> void f3(U); |
| 64 | |
| 65 | template<> void f3(int); |
Douglas Gregor | e8c01bd | 2009-10-30 21:07:27 +0000 | [diff] [blame] | 66 | |
| 67 | // PR5332 |
| 68 | template <typename T> |
| 69 | class Foo { |
| 70 | template <typename U> |
| 71 | friend class Foo; |
| 72 | }; |
| 73 | |
| 74 | Foo<int> foo; |
Douglas Gregor | 259571e | 2009-10-30 22:42:42 +0000 | [diff] [blame] | 75 | |
| 76 | template<typename T, T Value> |
| 77 | struct X2a; |
| 78 | |
| 79 | template<typename T, int Size> |
| 80 | struct X2b; |
| 81 | |
| 82 | template<typename T> |
| 83 | class X3 { |
| 84 | template<typename U, U Value> |
| 85 | friend struct X2a; |
| 86 | |
| 87 | template<typename U, T Value> |
| 88 | friend struct X2b; |
| 89 | }; |
| 90 | |
| 91 | X3<int> x3i; // okay |
| 92 | |
| 93 | X3<long> x3l; // FIXME: should cause an instantiation-time failure |