1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions %s
2*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions -std=c++11 %s
3*67e74705SXin Li
4*67e74705SXin Li template void *; // expected-error{{expected unqualified-id}}
5*67e74705SXin Li
6*67e74705SXin Li template typedef void f0; // expected-error{{explicit instantiation of typedef}}
7*67e74705SXin Li
8*67e74705SXin Li int v0; // expected-note{{refers here}}
9*67e74705SXin Li template int v0; // expected-error{{does not refer}}
10*67e74705SXin Li
11*67e74705SXin Li template<typename T>
12*67e74705SXin Li struct X0 {
13*67e74705SXin Li static T value;
14*67e74705SXin Li
f0X015*67e74705SXin Li T f0(T x) {
16*67e74705SXin Li return x + 1; // expected-error{{invalid operands}}
17*67e74705SXin Li }
f0X018*67e74705SXin Li 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'}}
19*67e74705SXin Li
f0X020*67e74705SXin Li 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'}} \
21*67e74705SXin Li // expected-note {{candidate template ignored: could not match 'int' against 'int *'}}
22*67e74705SXin Li };
23*67e74705SXin Li
24*67e74705SXin Li template<typename T>
25*67e74705SXin Li T X0<T>::value; // expected-error{{no matching constructor}}
26*67e74705SXin Li
27*67e74705SXin Li template int X0<int>::value;
28*67e74705SXin Li
29*67e74705SXin Li struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} expected-note 0-1 {{candidate constructor (the implicit move constructor)}}
30*67e74705SXin Li NotDefaultConstructible(int); // expected-note{{candidate constructor}}
31*67e74705SXin Li };
32*67e74705SXin Li
33*67e74705SXin Li template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}}
34*67e74705SXin Li
35*67e74705SXin Li template int X0<int>::f0(int);
36*67e74705SXin Li template int* X0<int>::f0(int*, int*); // expected-note{{in instantiation of member function 'X0<int>::f0' requested here}}
37*67e74705SXin Li template int X0<int>::f0(int, float);
38*67e74705SXin Li
39*67e74705SXin Li template int X0<int>::f0(int) const; // expected-error{{does not refer}}
40*67e74705SXin Li template int* X0<int>::f0(int*, float*); // expected-error{{does not refer}}
41*67e74705SXin Li
42*67e74705SXin Li struct X1 { };
43*67e74705SXin Li typedef int X1::*MemPtr;
44*67e74705SXin Li
45*67e74705SXin Li template MemPtr X0<MemPtr>::f0(MemPtr); // expected-note{{requested here}}
46*67e74705SXin Li
47*67e74705SXin Li struct X2 {
48*67e74705SXin Li int f0(int); // expected-note{{refers here}}
49*67e74705SXin Li
f1X250*67e74705SXin Li template<typename T> T f1(T) { return T(); }
f1X251*67e74705SXin Li template<typename T> T* f1(T*) { return 0; }
52*67e74705SXin Li
f2X253*67e74705SXin Li template<typename T, typename U> void f2(T, U*) { } // expected-note{{candidate}}
f2X254*67e74705SXin Li template<typename T, typename U> void f2(T*, U) { } // expected-note{{candidate}}
55*67e74705SXin Li };
56*67e74705SXin Li
57*67e74705SXin Li template int X2::f0(int); // expected-error{{not an instantiation}}
58*67e74705SXin Li
59*67e74705SXin Li template int *X2::f1(int *); // okay
60*67e74705SXin Li
61*67e74705SXin Li template void X2::f2(int *, int *); // expected-error{{ambiguous}}
62*67e74705SXin Li
63*67e74705SXin Li template <typename T>
print_type()64*67e74705SXin Li void print_type() {} // expected-note {{candidate template ignored: could not match 'void ()' against 'void (float *)'}}
65*67e74705SXin Li
66*67e74705SXin Li template void print_type<int>();
67*67e74705SXin Li template void print_type<float>();
68*67e74705SXin Li
69*67e74705SXin Li template <typename T>
print_type(T *)70*67e74705SXin Li void print_type(T *) {} // expected-note {{candidate template ignored: could not match 'void (int *)' against 'void (float *)'}}
71*67e74705SXin Li
72*67e74705SXin Li template void print_type(int*);
73*67e74705SXin Li template void print_type<int>(float*); // expected-error{{does not refer}}
74*67e74705SXin Li
75*67e74705SXin Li void print_type(double*);
76*67e74705SXin Li template void print_type<double>(double*);
77*67e74705SXin Li
78*67e74705SXin Li // PR5069
foo0(int (&)[I+1])79*67e74705SXin Li template<int I> void foo0 (int (&)[I + 1]) { }
80*67e74705SXin Li template void foo0<2> (int (&)[3]);
81*67e74705SXin Li
82*67e74705SXin Li namespace explicit_instantiation_after_implicit_instantiation {
83*67e74705SXin Li template <int I> struct X0 { static int x; };
84*67e74705SXin Li template <int I> int X0<I>::x;
test1()85*67e74705SXin Li void test1() { (void)&X0<1>::x; }
86*67e74705SXin Li template struct X0<1>;
87*67e74705SXin Li }
88*67e74705SXin Li
89*67e74705SXin Li template<typename> struct X3 { };
90*67e74705SXin Li inline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}}
91*67e74705SXin Li static template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}}
92*67e74705SXin Li
93*67e74705SXin Li namespace PR7622 {
94*67e74705SXin Li template<typename,typename=int>
95*67e74705SXin Li struct basic_streambuf;
96*67e74705SXin Li
97*67e74705SXin Li template<typename,typename>
98*67e74705SXin Li struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \
99*67e74705SXin Li // expected-error{{expected member name or ';' after declaration specifiers}}
100*67e74705SXin Li template struct basic_streambuf<int>;
101*67e74705SXin Li }
102*67e74705SXin Li
103*67e74705SXin Li // Test that we do not crash.
104*67e74705SXin Li class TC1 {
105*67e74705SXin Li class TC2 {
106*67e74705SXin Li template // FIXME: error here.
107*67e74705SXin Li void foo() { }
108*67e74705SXin Li };
109*67e74705SXin Li };
110*67e74705SXin Li
111*67e74705SXin Li namespace PR8020 {
112*67e74705SXin Li template <typename T> struct X { X() {} };
113*67e74705SXin Li template<> struct X<int> { X(); };
114*67e74705SXin Li template X<int>::X() {} // expected-error{{function cannot be defined in an explicit instantiation}}
115*67e74705SXin Li }
116*67e74705SXin Li
117*67e74705SXin Li namespace PR10086 {
118*67e74705SXin Li template void foobar(int i) {} // expected-error{{function cannot be defined in an explicit instantiation}}
119*67e74705SXin Li int func() {
120*67e74705SXin Li foobar(5);
121*67e74705SXin Li }
122*67e74705SXin Li }
123*67e74705SXin Li
124*67e74705SXin Li namespace undefined_static_data_member {
125*67e74705SXin Li template<typename T> struct A {
126*67e74705SXin Li static int a; // expected-note {{here}}
127*67e74705SXin Li template<typename U> static int b; // expected-note {{here}} expected-warning {{extension}}
128*67e74705SXin Li };
129*67e74705SXin Li struct B {
130*67e74705SXin Li template<typename U> static int c; // expected-note {{here}} expected-warning {{extension}}
131*67e74705SXin Li };
132*67e74705SXin Li
133*67e74705SXin Li 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*67e74705SXin Li template int A<int>::b<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::A<int>::b<int>'}}
135*67e74705SXin Li template int B::c<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::B::c<int>'}}
136*67e74705SXin Li
137*67e74705SXin Li
138*67e74705SXin Li template<typename T> struct C {
139*67e74705SXin Li static int a;
140*67e74705SXin Li template<typename U> static int b; // expected-warning {{extension}}
141*67e74705SXin Li };
142*67e74705SXin Li struct D {
143*67e74705SXin Li template<typename U> static int c; // expected-warning {{extension}}
144*67e74705SXin Li };
145*67e74705SXin Li template<typename T> int C<T>::a;
146*67e74705SXin Li template<typename T> template<typename U> int C<T>::b; // expected-warning {{extension}}
147*67e74705SXin Li template<typename U> int D::c; // expected-warning {{extension}}
148*67e74705SXin Li
149*67e74705SXin Li template int C<int>::a;
150*67e74705SXin Li template int C<int>::b<int>;
151*67e74705SXin Li template int D::c<int>;
152*67e74705SXin Li }
153*67e74705SXin Li
154*67e74705SXin Li // expected-note@+1 3-4 {{explicit instantiation refers here}}
155*67e74705SXin Li template <class T> void Foo(T i) throw(T) { throw i; }
156*67e74705SXin Li // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}}
157*67e74705SXin Li template void Foo(int a) throw(char);
158*67e74705SXin Li // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}}
159*67e74705SXin Li template void Foo(double a) throw();
160*67e74705SXin Li // expected-error@+1 1 {{exception specification in explicit instantiation does not match instantiated one}}
161*67e74705SXin Li template void Foo(long a) throw(long, char);
162*67e74705SXin Li template void Foo(float a);
163*67e74705SXin Li #if __cplusplus >= 201103L
164*67e74705SXin Li // expected-error@+1 0-1 {{exception specification in explicit instantiation does not match instantiated one}}
165*67e74705SXin Li template void Foo(double a) noexcept;
166*67e74705SXin Li #endif
167*67e74705SXin Li
168*67e74705SXin Li #if __cplusplus >= 201103L
169*67e74705SXin Li namespace PR21942 {
170*67e74705SXin Li template <int>
171*67e74705SXin Li struct A {
172*67e74705SXin Li virtual void foo() final;
173*67e74705SXin Li };
174*67e74705SXin Li
175*67e74705SXin Li template <>
176*67e74705SXin Li void A<0>::foo() {} // expected-note{{overridden virtual function is here}}
177*67e74705SXin Li
178*67e74705SXin Li struct B : A<0> {
179*67e74705SXin Li virtual void foo() override; // expected-error{{declaration of 'foo' overrides a 'final' function}}
180*67e74705SXin Li };
181*67e74705SXin Li }
182*67e74705SXin Li #endif
183