Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 2 | |
| 3 | template void *; // expected-error{{expected unqualified-id}} |
| 4 | |
| 5 | template typedef void f0; // expected-error{{explicit instantiation of typedef}} |
| 6 | |
| 7 | int v0; // expected-note{{refers here}} |
| 8 | template int v0; // expected-error{{does not refer}} |
| 9 | |
| 10 | template<typename T> |
| 11 | struct X0 { |
| 12 | static T value; |
| 13 | |
| 14 | T f0(T x) { |
| 15 | return x + 1; // expected-error{{invalid operands}} |
| 16 | } |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 17 | T* f0(T*, T*) { return T(); } |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 18 | |
| 19 | template<typename U> |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 20 | T f0(T, U) { return T(); } |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 23 | template<typename T> |
| 24 | T X0<T>::value; // expected-error{{no matching constructor}} |
| 25 | |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 26 | template int X0<int>::value; |
| 27 | |
John McCall | 220ccbf | 2010-01-13 00:25:19 +0000 | [diff] [blame] | 28 | struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} |
John McCall | b1622a1 | 2010-01-06 09:43:14 +0000 | [diff] [blame] | 29 | NotDefaultConstructible(int); // expected-note{{candidate constructor}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 32 | template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 33 | |
| 34 | template int X0<int>::f0(int); |
| 35 | template int* X0<int>::f0(int*, int*); |
| 36 | template int X0<int>::f0(int, float); |
| 37 | |
| 38 | template int X0<int>::f0(int) const; // expected-error{{does not refer}} |
| 39 | template int* X0<int>::f0(int*, float*); // expected-error{{does not refer}} |
| 40 | |
| 41 | struct X1 { }; |
| 42 | typedef int X1::*MemPtr; |
| 43 | |
| 44 | template MemPtr X0<MemPtr>::f0(MemPtr); // expected-note{{requested here}} |
| 45 | |
| 46 | struct X2 { |
| 47 | int f0(int); // expected-note{{refers here}} |
| 48 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 49 | template<typename T> T f1(T) { return T(); } |
| 50 | template<typename T> T* f1(T*) { return 0; } |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 51 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 52 | template<typename T, typename U> void f2(T, U*) { } // expected-note{{candidate}} |
| 53 | template<typename T, typename U> void f2(T*, U) { } // expected-note{{candidate}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | template int X2::f0(int); // expected-error{{not an instantiation}} |
| 57 | |
| 58 | template int *X2::f1(int *); // okay |
| 59 | |
| 60 | template void X2::f2(int *, int *); // expected-error{{ambiguous}} |
Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 61 | |
| 62 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 63 | template<typename T> void print_type() { } |
Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 64 | |
| 65 | template void print_type<int>(); |
| 66 | template void print_type<float>(); |
| 67 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 68 | template<typename T> void print_type(T*) { } |
Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 69 | |
| 70 | template void print_type(int*); |
| 71 | template void print_type<int>(float*); // expected-error{{does not refer}} |
| 72 | |
| 73 | void print_type(double*); |
| 74 | template void print_type<double>(double*); |
Douglas Gregor | b2f81cf | 2009-10-01 23:51:25 +0000 | [diff] [blame] | 75 | |
| 76 | // PR5069 |
| 77 | template<int I> void foo0 (int (&)[I + 1]) { } |
| 78 | template void foo0<2> (int (&)[3]); |
Chandler Carruth | 291b441 | 2010-02-13 10:17:50 +0000 | [diff] [blame] | 79 | |
| 80 | namespace explicit_instantiation_after_implicit_instantiation { |
| 81 | template <int I> struct X0 { static int x; }; |
| 82 | template <int I> int X0<I>::x; |
| 83 | void test1() { (void)&X0<1>::x; } |
| 84 | template struct X0<1>; |
| 85 | } |
Douglas Gregor | 669eed8 | 2010-07-13 00:10:04 +0000 | [diff] [blame] | 86 | |
Douglas Gregor | 7306ebf | 2010-12-01 20:32:20 +0000 | [diff] [blame] | 87 | template<typename> struct X3 { }; |
| 88 | inline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}} |
| 89 | static template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}} |
| 90 | |
Sebastian Redl | d941fa4 | 2011-04-24 16:27:48 +0000 | [diff] [blame] | 91 | namespace PR7622 { |
Douglas Gregor | 669eed8 | 2010-07-13 00:10:04 +0000 | [diff] [blame] | 92 | template<typename,typename=int> |
| 93 | struct basic_streambuf; |
| 94 | |
Douglas Gregor | 669eed8 | 2010-07-13 00:10:04 +0000 | [diff] [blame] | 95 | template<typename,typename> |
| 96 | struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \ |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 97 | // expected-error{{expected member name or ';' after declaration specifiers}} |
Sebastian Redl | d941fa4 | 2011-04-24 16:27:48 +0000 | [diff] [blame] | 98 | template struct basic_streambuf<int>; |
| 99 | } |
Argyrios Kyrtzidis | 9241057 | 2011-12-23 02:16:45 +0000 | [diff] [blame] | 100 | |
| 101 | // Test that we do not crash. |
| 102 | class TC1 { |
| 103 | class TC2 { |
| 104 | template // FIXME: error here. |
| 105 | void foo() { } |
| 106 | }; |
| 107 | }; |