1 // RUN: clang-cc -fsyntax-only -pedantic -verify %s
3 // Tests explicit instantiation of templates.
4 template<typename T, typename U = T> class X0 { };
7 template<typename T, typename U = T> class X1 { };
10 // Check the syntax of explicit instantiations.
11 template class X0<int, float>;
12 template class X0<int>; // expected-note{{previous}}
14 template class N::X1<int>;
15 template class ::N::X1<int, float>;
18 template class X1<float>;
20 // Check for some bogus syntax that probably means that the user
21 // wanted to write an explicit specialization, but forgot the '<>'
23 template class X0<double> { }; // expected-error{{explicit specialization}}
25 // Check for explicit instantiations that come after other kinds of
26 // instantiations or declarations.
27 template class X0<int, int>; // expected-error{{duplicate}}
29 template<> class X0<char> { }; // expected-note{{previous}}
30 template class X0<char>; // expected-warning{{ignored}}
32 void foo(X0<short>) { }
33 template class X0<short>;
35 // Check that explicit instantiations actually produce definitions. We
36 // determine whether this happens by placing semantic errors in the
37 // definition of the template we're instantiating.
38 template<typename T> struct X2; // expected-note{{declared here}}
40 template struct X2<float>; // expected-error{{undefined template}}
44 void f0(T*); // expected-error{{pointer to a reference}}
47 template struct X2<int>; // okay
48 template struct X2<int&>; // expected-note{{in instantiation of}}
50 // Check that explicit instantiations instantiate member classes.
51 template<typename T> struct X3 {
53 void f(T*); // expected-error{{pointer to a reference}}
57 void f1(X3<int&>); // okay, Inner, not instantiated
59 template struct X3<int&>; // expected-note{{instantiation}}
61 template<typename T> struct X4 {
64 void f(T*); // expected-error 2{{pointer to a reference}}
69 void f2(X4<int&>); // okay, Inner, not instantiated
70 void f3(X4<int&>::Inner); // okay, Inner::VeryInner, not instantiated
72 template struct X4<int&>; // expected-note{{instantiation}}
73 template struct X4<float&>; // expected-note{{instantiation}}
75 // Check explicit instantiation of member classes
86 void g(T*); // expected-error 2{{pointer to a reference}}
93 template struct N2::X5<void>::Inner2;
96 template struct X5<int&>::Inner2; // expected-note{{instantiation}}
98 void f4(X5<float&>::Inner2);
99 template struct X5<float&>::Inner2; // expected-note{{instantiation}}
102 template struct N2::X5<int>::Inner2;
106 struct Inner { // expected-note{{here}}
111 template struct X6::Inner; // expected-error{{non-templated}}