2009-05-13 07:25:50 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -verify %s
|
|
|
|
//
|
|
|
|
// Tests explicit instantiation of templates.
|
|
|
|
template<typename T, typename U = T> class X0 { };
|
|
|
|
|
|
|
|
namespace N {
|
|
|
|
template<typename T, typename U = T> class X1 { };
|
|
|
|
}
|
|
|
|
|
2009-05-13 08:25:59 +08:00
|
|
|
// Check the syntax of explicit instantiations.
|
2009-05-13 07:25:50 +08:00
|
|
|
template class X0<int, float>;
|
2009-05-13 08:25:59 +08:00
|
|
|
template class X0<int>; // expected-note{{previous}}
|
2009-05-13 07:25:50 +08:00
|
|
|
|
|
|
|
template class N::X1<int>;
|
|
|
|
template class ::N::X1<int, float>;
|
|
|
|
|
|
|
|
using namespace N;
|
|
|
|
template class X1<float>;
|
|
|
|
|
2009-05-13 08:25:59 +08:00
|
|
|
// Check for some bogus syntax that probably means that the user
|
|
|
|
// wanted to write an explicit specialization, but forgot the '<>'
|
|
|
|
// after 'template'.
|
2009-05-13 07:25:50 +08:00
|
|
|
template class X0<double> { }; // expected-error{{explicit specialization}}
|
2009-05-13 08:25:59 +08:00
|
|
|
|
|
|
|
// Check for explicit instantiations that come after other kinds of
|
|
|
|
// instantiations or declarations.
|
|
|
|
template class X0<int, int>; // expected-error{{after}}
|
|
|
|
|
|
|
|
template<> class X0<char> { }; // expected-note{{previous}}
|
|
|
|
template class X0<char>; // expected-error{{after}}
|
|
|
|
|
|
|
|
void foo(X0<short>) { } // expected-note{{previous}}
|
|
|
|
template class X0<short>; // expected-error{{after}}
|
|
|
|
|
|
|
|
// Check that explicit instantiations actually produce definitions. We
|
|
|
|
// determine whether this happens by placing semantic errors in the
|
|
|
|
// definition of the template we're instantiating.
|
|
|
|
template<typename T> struct X2; // expected-note{{declared here}}
|
|
|
|
|
|
|
|
template struct X2<float>; // expected-error{{undefined template}}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct X2 {
|
|
|
|
void f0(T*); // expected-error{{pointer to a reference}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct X2<int>; // okay
|
|
|
|
template struct X2<int&>; // expected-note{{in instantiation of}}
|