82 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s2 3// A declaration of a function template shall be in scope at the point of the 4// explicit instantiation of the function template.5template<typename T> void f0(T);6template void f0(int); // okay7template<typename T> void f0(T) { }8 9// A definition of the class or class template containing a member function 10// template shall be in scope at the point of the explicit instantiation of 11// the member function template.12struct X0; // expected-note {{forward declaration}}13template<typename> struct X1; // expected-note 5{{declared here}}14 15template void X0::f0<int>(int); // expected-error {{incomplete type}}16template void X1<int>::f0<int>(int); // expected-error {{implicit instantiation of undefined template}}17 18// A definition of a class template or class member template shall be in scope 19// at the point of the explicit instantiation of the class template or class 20// member template.21template struct X1<float>; // expected-error{{explicit instantiation of undefined template}}22 23template<typename T>24struct X2 { // expected-note 4{{refers here}}25 template<typename U>26 struct Inner; // expected-note{{declared here}}27 28 struct InnerClass; // expected-note{{forward declaration}}29};30 31template struct X2<int>::Inner<float>; // expected-error{{explicit instantiation of undefined template}}32 33// A definition of a class template shall be in scope at the point of an 34// explicit instantiation of a member function or a static data member of the35// class template.36template void X1<int>::f1(int); // expected-error {{undefined template}}37template void X1<int>::f1<int>(int); // expected-error {{undefined template}}38 39template int X1<int>::member; // expected-error {{undefined template}}40 41// A definition of a member class of a class template shall be in scope at the 42// point of an explicit instantiation of the member class.43template struct X2<float>::InnerClass; // expected-error{{undefined member}}44 45// If the declaration of the explicit instantiation names an implicitly-declared 46// special member function (Clause 12), the program is ill-formed.47template X2<int>::X2(); // expected-error{{not an instantiation}}48template X2<int>::X2(const X2&); // expected-error{{not an instantiation}}49template X2<int>::~X2(); // expected-error{{not an instantiation}}50template X2<int> &X2<int>::operator=(const X2<int>&); // expected-error{{not an instantiation}}51 52 53// A definition of a class template is sufficient to explicitly54// instantiate a member of the class template which itself is not yet defined.55namespace PR7979 {56 template <typename T> struct S {57 void f();58 static void g();59 static int i;60 struct S2 {61 void h();62 };63 };64 65 template void S<int>::f();66 template void S<int>::g();67 template int S<int>::i;68 template void S<int>::S2::h();69 70 template <typename T> void S<T>::f() {}71 template <typename T> void S<T>::g() {}72 template <typename T> int S<T>::i;73 template <typename T> void S<T>::S2::h() {}74}75 76namespace PR11599 {77 template <typename STRING_TYPE> class BasicStringPiece; // expected-note {{template is declared here}}78 79 extern template class BasicStringPiece<int>; // expected-error{{explicit instantiation of undefined template 'PR11599::BasicStringPiece<int>}}80 template class BasicStringPiece<int>;81}82