Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 2 | |
| 3 | // Tests various places where requiring a complete type involves |
| 4 | // instantiation of that type. |
| 5 | |
| 6 | template<typename T> |
| 7 | struct X { |
| 8 | X(T); |
| 9 | |
| 10 | T f; // expected-error{{data member instantiated with function type 'float (int)'}} \ |
| 11 | // expected-error{{data member instantiated with function type 'int (int)'}} \ |
| 12 | // expected-error{{data member instantiated with function type 'char (char)'}} \ |
| 13 | // expected-error{{data member instantiated with function type 'short (short)'}} \ |
Sebastian Redl | 59fc269 | 2010-04-10 10:14:54 +0000 | [diff] [blame] | 14 | // expected-error{{data member instantiated with function type 'float (float)'}} \ |
| 15 | // expected-error{{data member instantiated with function type 'long (long)'}} |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | X<int> f() { return 0; } |
| 19 | |
| 20 | struct XField { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 21 | X<float(int)> xf; // expected-note{{in instantiation of template class 'X<float (int)>' requested here}} |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | void test_subscript(X<double> *ptr1, X<int(int)> *ptr2, int i) { |
| 25 | (void)ptr1[i]; |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 26 | (void)ptr2[i]; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}} |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void test_arith(X<signed char> *ptr1, X<unsigned char> *ptr2, |
| 30 | X<char(char)> *ptr3, X<short(short)> *ptr4) { |
| 31 | (void)(ptr1 + 5); |
| 32 | // FIXME: if I drop the ')' after void, below, it still parses (!) |
| 33 | (void)(5 + ptr2); |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 34 | (void)(ptr3 + 5); // expected-note{{in instantiation of template class 'X<char (char)>' requested here}} |
| 35 | (void)(5 + ptr4); // expected-note{{in instantiation of template class 'X<short (short)>' requested here}} |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void test_new() { |
| 39 | (void)new X<float>(0); |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 40 | (void)new X<float(float)>; // expected-note{{in instantiation of template class 'X<float (float)>' requested here}} |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void test_memptr(X<long> *p1, long X<long>::*pm1, |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 44 | X<long(long)> *p2, |
| 45 | long (X<long(long)>::*pm2)(long)) { |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 46 | (void)(p1->*pm1); |
Sebastian Redl | 59fc269 | 2010-04-10 10:14:54 +0000 | [diff] [blame] | 47 | (void)((p2->*pm2)(0)); // expected-note{{in instantiation of template class 'X<long (long)>' requested here}} |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 48 | } |
Douglas Gregor | 393896f | 2009-11-05 13:06:35 +0000 | [diff] [blame] | 49 | |
| 50 | // Reference binding to a base |
| 51 | template<typename T> |
| 52 | struct X1 { }; |
| 53 | |
| 54 | template<typename T> |
| 55 | struct X2 : public T { }; |
| 56 | |
| 57 | void refbind_base(X2<X1<int> > &x2) { |
| 58 | X1<int> &x1 = x2; |
| 59 | } |
| 60 | |
| 61 | // Enumerate constructors for user-defined conversion. |
| 62 | template<typename T> |
| 63 | struct X3 { |
| 64 | X3(T); |
| 65 | }; |
| 66 | |
| 67 | void enum_constructors(X1<float> &x1) { |
| 68 | X3<X1<float> > x3 = x1; |
| 69 | } |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 70 | |
| 71 | namespace PR6376 { |
| 72 | template<typename T, typename U> struct W { }; |
| 73 | |
| 74 | template<typename T> |
| 75 | struct X { |
| 76 | template<typename U> |
| 77 | struct apply { |
| 78 | typedef W<T, U> type; |
| 79 | }; |
| 80 | }; |
| 81 | |
| 82 | template<typename T, typename U> |
| 83 | struct Y : public X<T>::template apply<U>::type { }; |
| 84 | |
| 85 | template struct Y<int, float>; |
| 86 | } |
Douglas Gregor | f86fcb3 | 2010-04-24 21:09:25 +0000 | [diff] [blame] | 87 | |
| 88 | namespace TemporaryObjectCopy { |
| 89 | // Make sure we instantiate classes when we create a temporary copy. |
| 90 | template<typename T> |
| 91 | struct X { |
| 92 | X(T); |
| 93 | }; |
| 94 | |
| 95 | template<typename T> |
| 96 | void f(T t) { |
| 97 | const X<int> &x = X<int>(t); |
| 98 | } |
| 99 | |
| 100 | template void f(int); |
| 101 | } |
Douglas Gregor | 6b6d01f | 2010-05-07 19:42:26 +0000 | [diff] [blame^] | 102 | |
| 103 | namespace PR7080 { |
| 104 | template <class T, class U> |
| 105 | class X |
| 106 | { |
| 107 | typedef char true_t; |
| 108 | class false_t { char dummy[2]; }; |
| 109 | static true_t dispatch(U); |
| 110 | static false_t dispatch(...); |
| 111 | static T trigger(); |
| 112 | public: |
| 113 | enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) }; |
| 114 | }; |
| 115 | |
| 116 | template <class T> |
| 117 | class rv : public T |
| 118 | { }; |
| 119 | |
| 120 | bool x = X<int, rv<int>&>::value; |
| 121 | } |