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