Douglas Gregor | f61eca9 | 2009-05-13 18:28:20 +0000 | [diff] [blame^] | 1 | // RUN: clang-cc -fsyntax-only -verify -pedantic %s |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 2 | // |
| 3 | // Tests explicit instantiation of templates. |
| 4 | template<typename T, typename U = T> class X0 { }; |
| 5 | |
| 6 | namespace N { |
| 7 | template<typename T, typename U = T> class X1 { }; |
| 8 | } |
| 9 | |
Douglas Gregor | a1f4997 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 10 | // Check the syntax of explicit instantiations. |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 11 | template class X0<int, float>; |
Douglas Gregor | a1f4997 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 12 | template class X0<int>; // expected-note{{previous}} |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 13 | |
| 14 | template class N::X1<int>; |
| 15 | template class ::N::X1<int, float>; |
| 16 | |
| 17 | using namespace N; |
| 18 | template class X1<float>; |
| 19 | |
Douglas Gregor | a1f4997 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 20 | // 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 Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 23 | template class X0<double> { }; // expected-error{{explicit specialization}} |
Douglas Gregor | a1f4997 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 24 | |
| 25 | // Check for explicit instantiations that come after other kinds of |
| 26 | // instantiations or declarations. |
Douglas Gregor | f61eca9 | 2009-05-13 18:28:20 +0000 | [diff] [blame^] | 27 | template class X0<int, int>; // expected-error{{duplicate}} |
Douglas Gregor | a1f4997 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 28 | |
| 29 | template<> class X0<char> { }; // expected-note{{previous}} |
Douglas Gregor | f61eca9 | 2009-05-13 18:28:20 +0000 | [diff] [blame^] | 30 | template class X0<char>; // expected-warning{{ignored}} |
Douglas Gregor | a1f4997 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 31 | |
Douglas Gregor | f61eca9 | 2009-05-13 18:28:20 +0000 | [diff] [blame^] | 32 | void foo(X0<short>) { } |
| 33 | template class X0<short>; |
Douglas Gregor | a1f4997 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 34 | |
| 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}} |
| 39 | |
| 40 | template struct X2<float>; // expected-error{{undefined template}} |
| 41 | |
| 42 | template<typename T> |
| 43 | struct X2 { |
| 44 | void f0(T*); // expected-error{{pointer to a reference}} |
| 45 | }; |
| 46 | |
| 47 | template struct X2<int>; // okay |
| 48 | template struct X2<int&>; // expected-note{{in instantiation of}} |