blob: b6009bd9c164a38d587e94736777d1681993bd4e [file] [log] [blame]
Douglas Gregorf61eca92009-05-13 18:28:20 +00001// RUN: clang-cc -fsyntax-only -verify -pedantic %s
Douglas Gregor1b57ff32009-05-12 23:25:50 +00002//
3// Tests explicit instantiation of templates.
4template<typename T, typename U = T> class X0 { };
5
6namespace N {
7 template<typename T, typename U = T> class X1 { };
8}
9
Douglas Gregora1f49972009-05-13 00:25:59 +000010// Check the syntax of explicit instantiations.
Douglas Gregor1b57ff32009-05-12 23:25:50 +000011template class X0<int, float>;
Douglas Gregora1f49972009-05-13 00:25:59 +000012template class X0<int>; // expected-note{{previous}}
Douglas Gregor1b57ff32009-05-12 23:25:50 +000013
14template class N::X1<int>;
15template class ::N::X1<int, float>;
16
17using namespace N;
18template class X1<float>;
19
Douglas Gregora1f49972009-05-13 00:25:59 +000020// Check for some bogus syntax that probably means that the user
21// wanted to write an explicit specialization, but forgot the '<>'
22// after 'template'.
Douglas Gregor1b57ff32009-05-12 23:25:50 +000023template class X0<double> { }; // expected-error{{explicit specialization}}
Douglas Gregora1f49972009-05-13 00:25:59 +000024
25// Check for explicit instantiations that come after other kinds of
26// instantiations or declarations.
Douglas Gregorf61eca92009-05-13 18:28:20 +000027template class X0<int, int>; // expected-error{{duplicate}}
Douglas Gregora1f49972009-05-13 00:25:59 +000028
29template<> class X0<char> { }; // expected-note{{previous}}
Douglas Gregorf61eca92009-05-13 18:28:20 +000030template class X0<char>; // expected-warning{{ignored}}
Douglas Gregora1f49972009-05-13 00:25:59 +000031
Douglas Gregorf61eca92009-05-13 18:28:20 +000032void foo(X0<short>) { }
33template class X0<short>;
Douglas Gregora1f49972009-05-13 00:25:59 +000034
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.
38template<typename T> struct X2; // expected-note{{declared here}}
39
40template struct X2<float>; // expected-error{{undefined template}}
41
42template<typename T>
43struct X2 {
44 void f0(T*); // expected-error{{pointer to a reference}}
45};
46
47template struct X2<int>; // okay
48template struct X2<int&>; // expected-note{{in instantiation of}}