| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions -Wno-dynamic-exception-spec -pedantic %std_cxx11- %s |
| 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 |
} |
| 17 |
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'}} |
| 18 |
|
| 19 |
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'}} \ |
| 20 |
// expected-note {{candidate template ignored: could not match 'int' against 'int *'}} |
| 21 |
}; |
| 22 |
|
| 23 |
template<typename T> |
| 24 |
T X0<T>::value; // expected-error{{no matching constructor}} |
| 25 |
|
| 26 |
template int X0<int>::value; |
| 27 |
|
| 28 |
struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} expected-note 0-1 {{candidate constructor (the implicit move constructor)}} |
| 29 |
NotDefaultConstructible(int); // expected-note{{candidate constructor}} |
| 30 |
}; |
| 31 |
|
| 32 |
template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}} |
| 33 |
|
| 34 |
template int X0<int>::f0(int); |
| 35 |
template int* X0<int>::f0(int*, int*); // expected-note{{in instantiation of member function 'X0<int>::f0' requested here}} |
| 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 |
|
| 49 |
template<typename T> T f1(T) { return T(); } |
| 50 |
template<typename T> T* f1(T*) { return 0; } |
| 51 |
|
| 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}} |
| 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}} |
| 61 |
|
| 62 |
template <typename T> |
| 63 |
void print_type() {} // expected-note {{candidate template ignored: could not match 'void ()' against 'void (float *)'}} |
| 64 |
|
| 65 |
template void print_type<int>(); |
| 66 |
template void print_type<float>(); |
| 67 |
|
| 68 |
template <typename T> |
| 69 |
void print_type(T *) {} // expected-note {{candidate template ignored: could not match 'void (int *)' against 'void (float *)'}} |
| 70 |
|
| 71 |
template void print_type(int*); |
| 72 |
template void print_type<int>(float*); // expected-error{{does not refer}} |
| 73 |
|
| 74 |
void print_type(double*); |
| 75 |
template void print_type<double>(double*); |
| 76 |
|
| 77 |
// PR5069 |
| 78 |
template<int I> void foo0 (int (&)[I + 1]) { } |
| 79 |
template void foo0<2> (int (&)[3]); |
| 80 |
|
| 81 |
namespace explicit_instantiation_after_implicit_instantiation { |
| 82 |
template <int I> struct X0 { static int x; }; |
| 83 |
template <int I> int X0<I>::x; |
| 84 |
void test1() { (void)&X0<1>::x; } |
| 85 |
template struct X0<1>; |
| 86 |
} |
| 87 |
|
| 88 |
template<typename> struct X3 { }; |
| 89 |
inline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}} |
| 90 |
static template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}} |
| 91 |
|
| 92 |
namespace PR7622 { |
| 93 |
template<typename,typename=int> |
| 94 |
struct basic_streambuf; |
| 95 |
|
| 96 |
template<typename,typename> |
| 97 |
struct basic_streambuf{friend bob<>()}; // expected-error{{no template named 'bob'}} \ |
| 98 |
// expected-error{{expected member name or ';' after declaration specifiers}} |
| 99 |
template struct basic_streambuf<int>; |
| 100 |
} |
| 101 |
|
| 102 |
// Test that we do not crash. |
| 103 |
class TC1 { |
| 104 |
class TC2 { |
| 105 |
template |
| 106 |
void foo() { } // expected-error{{expected '<' after 'template'}} |
| 107 |
}; |
| 108 |
}; |
| 109 |
|
| 110 |
namespace PR8020 { |
| 111 |
template <typename T> struct X { X() {} }; |
| 112 |
template<> struct X<int> { X(); }; |
| 113 |
template X<int>::X() {} // expected-error{{function cannot be defined in an explicit instantiation}} |
| 114 |
} |
| 115 |
|
| 116 |
namespace PR10086 { |
| 117 |
template void foobar(int i) {} // expected-error{{function cannot be defined in an explicit instantiation}} |
| 118 |
int func() { |
| 119 |
foobar(5); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
namespace undefined_static_data_member { |
| 124 |
template<typename T> struct A { |
| 125 |
static int a; // expected-note {{here}} |
| 126 |
template<typename U> static int b; // expected-note {{here}} expected-warning 0+ {{extension}} |
| 127 |
}; |
| 128 |
struct B { |
| 129 |
template<typename U> static int c; // expected-note {{here}} expected-warning 0+ {{extension}} |
| 130 |
}; |
| 131 |
|
| 132 |
template int A<int>::a; // expected-error {{explicit instantiation of undefined static data member 'a' of class template 'undefined_static_data_member::A<int>'}} |
| 133 |
template int A<int>::b<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::A<int>::b<int>'}} |
| 134 |
template int B::c<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::B::c<int>'}} |
| 135 |
|
| 136 |
|
| 137 |
template<typename T> struct C { |
| 138 |
static int a; |
| 139 |
template<typename U> static int b; // expected-warning 0+ {{extension}} |
| 140 |
}; |
| 141 |
struct D { |
| 142 |
template<typename U> static int c; // expected-warning 0+ {{extension}} |
| 143 |
}; |
| 144 |
template<typename T> int C<T>::a; |
| 145 |
template<typename T> template<typename U> int C<T>::b; // expected-warning 0+ {{extension}} |
| 146 |
template<typename U> int D::c; // expected-warning 0+ {{extension}} |
| 147 |
|
| 148 |
template int C<int>::a; |
| 149 |
template int C<int>::b<int>; |
| 150 |
template int D::c<int>; |
| 151 |
} |
| 152 |
|
| 153 |
// expected-note@+1 3-4 {{explicit instantiation refers here}} |
| 154 |
template <class T> void Foo(T i) throw(T) { throw i; } |
| 155 |
// expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 156 |
template void Foo(int a) throw(char); |
| 157 |
// expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 158 |
template void Foo(double a) throw(); |
| 159 |
// expected-error@+1 1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 160 |
template void Foo(long a) throw(long, char); |
| 161 |
template void Foo(float a); |
| 162 |
#if __cplusplus >= 201103L |
| 163 |
// expected-error@+1 0-1 {{exception specification in explicit instantiation does not match instantiated one}} |
| 164 |
template void Foo(double a) noexcept; |
| 165 |
#endif |
| 166 |
|
| 167 |
#if __cplusplus >= 201103L |
| 168 |
namespace PR21942 { |
| 169 |
template <int> |
| 170 |
struct A { |
| 171 |
virtual void foo() final; |
| 172 |
}; |
| 173 |
|
| 174 |
template <> |
| 175 |
void A<0>::foo() {} // expected-note{{overridden virtual function is here}} |
| 176 |
|
| 177 |
struct B : A<0> { |
| 178 |
virtual void foo() override; // expected-error{{declaration of 'foo' overrides a 'final' function}} |
| 179 |
}; |
| 180 |
} |
| 181 |
|
| 182 |
template<typename T> struct LambdaInDefaultMemberInitInExplicitInstantiation { |
| 183 |
int a = [this] { return a; }(); |
| 184 |
}; |
| 185 |
template struct LambdaInDefaultMemberInitInExplicitInstantiation<int>; |
| 186 |
LambdaInDefaultMemberInitInExplicitInstantiation<float> x; |
| 187 |
#endif |
| 188 |
|
| 189 |
namespace Qualified { |
| 190 |
template <class> struct C { |
| 191 |
struct D { |
| 192 |
void f(); |
| 193 |
}; |
| 194 |
}; |
| 195 |
extern template void C<int>::D::f(); |
| 196 |
} |