p3.cpp revision 3f9a0566e6793151b99a65ab936220971cf96c1b
1// RUN: clang-cc -fsyntax-only -verify %s 2 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); // okay 7 8// A definition of the class or class template containing a member function 9// template shall be in scope at the point of the explicit instantiation of 10// the member function template. 11struct X0; // expected-note 2{{forward declaration}} 12template<typename> struct X1; // expected-note 5{{declared here}} 13 14// FIXME: Repeated diagnostics here! 15template void X0::f0<int>(int); // expected-error 2{{incomplete type}} \ 16 // expected-error{{does not refer}} 17template void X1<int>::f0<int>(int); // expected-error 2{{implicit instantiation of undefined template}} \ 18 // expected-error{{does not refer}} 19 20// A definition of a class template or class member template shall be in scope 21// at the point of the explicit instantiation of the class template or class 22// member template. 23template struct X1<float>; // expected-error{{explicit instantiation of undefined template}} 24 25template<typename T> 26struct X2 { // expected-note 4{{refers here}} 27 template<typename U> 28 struct Inner; // expected-note{{declared here}} 29 30 struct InnerClass; // expected-note{{forward declaration}} 31}; 32 33template struct X2<int>::Inner<float>; // expected-error{{explicit instantiation of undefined template}} 34 35// A definition of a class template shall be in scope at the point of an 36// explicit instantiation of a member function or a static data member of the 37// class template. 38template void X1<int>::f1(int); // expected-error{{undefined template}} \ 39 // expected-error{{does not refer}} 40 41template int X1<int>::member; // expected-error{{undefined template}} \ 42 // expected-error{{does not refer}} 43 44// A definition of a member class of a class template shall be in scope at the 45// point of an explicit instantiation of the member class. 46template struct X2<float>::InnerClass; // expected-error{{undefined member}} 47 48// If the declaration of the explicit instantiation names an implicitly-declared 49// special member function (Clause 12), the program is ill-formed. 50template X2<int>::X2(); // expected-error{{not an instantiation}} 51template X2<int>::X2(const X2&); // expected-error{{not an instantiation}} 52template X2<int>::~X2(); // expected-error{{not an instantiation}} 53template X2<int> &X2<int>::operator=(const X2<int>&); // expected-error{{not an instantiation}} 54