Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions -std=c++11 %s |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 3 | |
| 4 | template void *; // expected-error{{expected unqualified-id}} |
| 5 | |
| 6 | template typedef void f0; // expected-error{{explicit instantiation of typedef}} |
| 7 | |
| 8 | int v0; // expected-note{{refers here}} |
| 9 | template int v0; // expected-error{{does not refer}} |
| 10 | |
| 11 | template<typename T> |
| 12 | struct X0 { |
| 13 | static T value; |
| 14 | |
| 15 | T f0(T x) { |
| 16 | return x + 1; // expected-error{{invalid operands}} |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 17 | } |
| 18 | T *f0(T *, T *) { return T(); } // expected-warning 0-1 {{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} expected-error 0-1 {{cannot initialize return object of type 'int *' with an rvalue of type 'int'}} |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 19 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 20 | template <typename U> T f0(T, U) { return T(); } // expected-note-re {{candidate template ignored: could not match 'int (int, U){{( __attribute__\(\(thiscall\)\))?}}' against 'int (int){{( __attribute__\(\(thiscall\)\))?}} const'}} \ |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 21 | // expected-note {{candidate template ignored: could not match 'int' against 'int *'}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 24 | template<typename T> |
| 25 | T X0<T>::value; // expected-error{{no matching constructor}} |
| 26 | |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 27 | template int X0<int>::value; |
| 28 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 29 | struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} expected-note 0-1 {{candidate constructor (the implicit move constructor)}} |
John McCall | b1622a1 | 2010-01-06 09:43:14 +0000 | [diff] [blame] | 30 | NotDefaultConstructible(int); // expected-note{{candidate constructor}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 33 | template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 34 | |
| 35 | template int X0<int>::f0(int); |
David Blaikie | 50800fc | 2012-08-08 17:33:31 +0000 | [diff] [blame] | 36 | template int* X0<int>::f0(int*, int*); // expected-note{{in instantiation of member function 'X0<int>::f0' requested here}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 37 | template int X0<int>::f0(int, float); |
| 38 | |
| 39 | template int X0<int>::f0(int) const; // expected-error{{does not refer}} |
| 40 | template int* X0<int>::f0(int*, float*); // expected-error{{does not refer}} |
| 41 | |
| 42 | struct X1 { }; |
| 43 | typedef int X1::*MemPtr; |
| 44 | |
| 45 | template MemPtr X0<MemPtr>::f0(MemPtr); // expected-note{{requested here}} |
| 46 | |
| 47 | struct X2 { |
| 48 | int f0(int); // expected-note{{refers here}} |
| 49 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 50 | template<typename T> T f1(T) { return T(); } |
| 51 | template<typename T> T* f1(T*) { return 0; } |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 52 | |
Douglas Gregor | 558c032 | 2009-10-14 23:41:34 +0000 | [diff] [blame] | 53 | template<typename T, typename U> void f2(T, U*) { } // expected-note{{candidate}} |
| 54 | template<typename T, typename U> void f2(T*, U) { } // expected-note{{candidate}} |
Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | template int X2::f0(int); // expected-error{{not an instantiation}} |
| 58 | |
| 59 | template int *X2::f1(int *); // okay |
| 60 | |
| 61 | template void X2::f2(int *, int *); // expected-error{{ambiguous}} |
Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 62 | |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 63 | template <typename T> |
| 64 | void print_type() {} // expected-note {{candidate template ignored: could not match 'void ()' against 'void (float *)'}} |
Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 65 | |
| 66 | template void print_type<int>(); |
| 67 | template void print_type<float>(); |
| 68 | |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 69 | template <typename T> |
| 70 | void print_type(T *) {} // expected-note {{candidate template ignored: could not match 'void (int *)' against 'void (float *)'}} |
Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 71 | |
| 72 | template void print_type(int*); |
| 73 | template void print_type<int>(float*); // expected-error{{does not refer}} |
| 74 | |
| 75 | void print_type(double*); |
| 76 | template void print_type<double>(double*); |
Douglas Gregor | b2f81cf | 2009-10-01 23:51:25 +0000 | [diff] [blame] | 77 | |
| 78 | // PR5069 |
| 79 | template<int I> void foo0 (int (&)[I + 1]) { } |
| 80 | template void foo0<2> (int (&)[3]); |
Chandler Carruth | 291b441 | 2010-02-13 10:17:50 +0000 | [diff] [blame] | 81 | |
| 82 | namespace explicit_instantiation_after_implicit_instantiation { |
| 83 | template <int I> struct X0 { static int x; }; |
| 84 | template <int I> int X0<I>::x; |
| 85 | void test1() { (void)&X0<1>::x; } |
| 86 | template struct X0<1>; |
| 87 | } |
Douglas Gregor | 669eed8 | 2010-07-13 00:10:04 +0000 | [diff] [blame] | 88 | |
Douglas Gregor | 7306ebf | 2010-12-01 20:32:20 +0000 | [diff] [blame] | 89 | template<typename> struct X3 { }; |
| 90 | inline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}} |
| 91 | static template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}} |
| 92 | |
Sebastian Redl | d941fa4 | 2011-04-24 16:27:48 +0000 | [diff] [blame] | 93 | namespace PR7622 { |
Douglas Gregor | 669eed8 | 2010-07-13 00:10:04 +0000 | [diff] [blame] | 94 | template<typename,typename=int> |
| 95 | struct basic_streambuf; |
| 96 | |
Douglas Gregor | 669eed8 | 2010-07-13 00:10:04 +0000 | [diff] [blame] | 97 | template<typename,typename> |
| 98 | struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \ |
Larisse Voufo | 4384712 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 99 | // expected-error{{expected member name or ';' after declaration specifiers}} |
Sebastian Redl | d941fa4 | 2011-04-24 16:27:48 +0000 | [diff] [blame] | 100 | template struct basic_streambuf<int>; |
| 101 | } |
Argyrios Kyrtzidis | 9241057 | 2011-12-23 02:16:45 +0000 | [diff] [blame] | 102 | |
| 103 | // Test that we do not crash. |
| 104 | class TC1 { |
| 105 | class TC2 { |
| 106 | template // FIXME: error here. |
| 107 | void foo() { } |
| 108 | }; |
| 109 | }; |
Serge Pavlov | 313a9f4 | 2013-09-11 17:04:24 +0000 | [diff] [blame] | 110 | |
| 111 | namespace PR8020 { |
| 112 | template <typename T> struct X { X() {} }; |
| 113 | template<> struct X<int> { X(); }; |
| 114 | template X<int>::X() {} // expected-error{{function cannot be defined in an explicit instantiation}} |
| 115 | } |
| 116 | |
| 117 | namespace PR10086 { |
| 118 | template void foobar(int i) {} // expected-error{{function cannot be defined in an explicit instantiation}} |
| 119 | int func() { |
| 120 | foobar(5); |
| 121 | } |
| 122 | } |
Richard Smith | d0629eb | 2013-09-27 20:14:12 +0000 | [diff] [blame] | 123 | |
| 124 | namespace undefined_static_data_member { |
| 125 | template<typename T> struct A { |
| 126 | static int a; // expected-note {{here}} |
| 127 | template<typename U> static int b; // expected-note {{here}} expected-warning {{extension}} |
| 128 | }; |
| 129 | struct B { |
| 130 | template<typename U> static int c; // expected-note {{here}} expected-warning {{extension}} |
| 131 | }; |
| 132 | |
| 133 | template int A<int>::a; // expected-error {{explicit instantiation of undefined static data member 'a' of class template 'undefined_static_data_member::A<int>'}} |
| 134 | template int A<int>::b<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::A<int>::b<int>'}} |
| 135 | template int B::c<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::B::c<int>'}} |
| 136 | |
| 137 | |
| 138 | template<typename T> struct C { |
| 139 | static int a; |
| 140 | template<typename U> static int b; // expected-warning {{extension}} |
| 141 | }; |
| 142 | struct D { |
| 143 | template<typename U> static int c; // expected-warning {{extension}} |
| 144 | }; |
| 145 | template<typename T> int C<T>::a; |
| 146 | template<typename T> template<typename U> int C<T>::b; // expected-warning {{extension}} |
| 147 | template<typename U> int D::c; // expected-warning {{extension}} |
| 148 | |
| 149 | template int C<int>::a; |
| 150 | template int C<int>::b<int>; |
| 151 | template int D::c<int>; |
| 152 | } |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 153 | |
| 154 | // expected-note@+1 3-4 {{explicit instantiation refers here}} |
| 155 | template <class T> void Foo(T i) throw(T) { throw i; } |
| 156 | // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 157 | template void Foo(int a) throw(char); |
| 158 | // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 159 | template void Foo(double a) throw(); |
| 160 | // expected-error@+1 1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 161 | template void Foo(long a) throw(long, char); |
| 162 | template void Foo(float a); |
| 163 | #if __cplusplus >= 201103L |
| 164 | // expected-error@+1 0-1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 165 | template void Foo(double a) noexcept; |
| 166 | #endif |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 167 | |
| 168 | #if __cplusplus >= 201103L |
| 169 | namespace PR21942 { |
| 170 | template <int> |
| 171 | struct A { |
| 172 | virtual void foo() final; |
| 173 | }; |
| 174 | |
| 175 | template <> |
| 176 | void A<0>::foo() {} // expected-note{{overridden virtual function is here}} |
| 177 | |
| 178 | struct B : A<0> { |
| 179 | virtual void foo() override; // expected-error{{declaration of 'foo' overrides a 'final' function}} |
| 180 | }; |
| 181 | } |
| 182 | #endif |