Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
| 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)'}} \ |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame^] | 14 | // expected-error{{data member instantiated with function type 'float (float)'}} |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 15 | }; |
| 16 | |
| 17 | X<int> f() { return 0; } |
| 18 | |
| 19 | struct XField { |
| 20 | X<float(int)> xf; // expected-note{{in instantiation of template class 'struct X<float (int)>' requested here}} |
| 21 | }; |
| 22 | |
| 23 | void test_subscript(X<double> *ptr1, X<int(int)> *ptr2, int i) { |
| 24 | (void)ptr1[i]; |
| 25 | (void)ptr2[i]; // expected-note{{in instantiation of template class 'struct X<int (int)>' requested here}} |
| 26 | } |
| 27 | |
| 28 | void test_arith(X<signed char> *ptr1, X<unsigned char> *ptr2, |
| 29 | X<char(char)> *ptr3, X<short(short)> *ptr4) { |
| 30 | (void)(ptr1 + 5); |
| 31 | // FIXME: if I drop the ')' after void, below, it still parses (!) |
| 32 | (void)(5 + ptr2); |
| 33 | (void)(ptr3 + 5); // expected-note{{in instantiation of template class 'struct X<char (char)>' requested here}} |
| 34 | (void)(5 + ptr4); // expected-note{{in instantiation of template class 'struct X<short (short)>' requested here}} |
| 35 | } |
| 36 | |
| 37 | void test_new() { |
| 38 | (void)new X<float>(0); |
| 39 | (void)new X<float(float)>; // expected-note{{in instantiation of template class 'struct X<float (float)>' requested here}} |
| 40 | } |
| 41 | |
| 42 | void test_memptr(X<long> *p1, long X<long>::*pm1, |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame^] | 43 | X<long(long)> *p2, |
| 44 | long (X<long(long)>::*pm2)(long)) { |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 45 | (void)(p1->*pm1); |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame^] | 46 | (void)((p2->*pm2)(0)); |
Douglas Gregor | e7450f5 | 2009-03-24 19:52:54 +0000 | [diff] [blame] | 47 | } |