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