Home | History | Annotate | Download | only in temp.explicit
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 struct C { };
      4 
      5 template<typename T>
      6 struct X0 {
      7   T value; // expected-error{{incomplete}}
      8 };
      9 
     10 // Explicitly instantiate a class template specialization
     11 template struct X0<int>;
     12 template struct X0<void>; // expected-note{{instantiation}}
     13 
     14 // Explicitly instantiate a function template specialization
     15 template<typename T>
     16 void f0(T t) {
     17   ++t; // expected-error{{cannot increment}}
     18 }
     19 
     20 template void f0(int);
     21 template void f0<long>(long);
     22 template void f0<>(unsigned);
     23 template void f0(int C::*); // expected-note{{instantiation}}
     24 
     25 // Explicitly instantiate a member template specialization
     26 template<typename T>
     27 struct X1 {
     28   template<typename U>
     29   struct Inner {
     30     T member1;
     31     U member2; // expected-error{{incomplete}}
     32   };
     33 
     34   template<typename U>
     35   void f(T& t, U u) {
     36     t = u; // expected-error{{incompatible}}
     37   }
     38 };
     39 
     40 template struct X1<int>::Inner<float>;
     41 template struct X1<int>::Inner<double>;
     42 template struct X1<int>::Inner<void>; // expected-note{{instantiation}}
     43 
     44 template void X1<int>::f(int&, float);
     45 template void X1<int>::f<long>(int&, long);
     46 template void X1<int>::f<>(int&, double);
     47 template void X1<int>::f<>(int&, int*); // expected-note{{instantiation}}
     48 
     49 // Explicitly instantiate members of a class template
     50 struct Incomplete; // expected-note{{forward declaration}}
     51 struct NonDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor) not viable}}
     52   NonDefaultConstructible(int); // expected-note{{candidate constructor}}
     53 };
     54 
     55 template<typename T, typename U>
     56 struct X2 {
     57   void f(T &t, U u) {
     58     t = u; // expected-error{{incompatible}}
     59   }
     60 
     61   struct Inner {
     62     T member1;
     63     U member2; // expected-error{{incomplete}}
     64   };
     65 
     66   static T static_member1;
     67   static U static_member2;
     68 };
     69 
     70 template<typename T, typename U>
     71 T X2<T, U>::static_member1 = 17; // expected-error{{cannot initialize}}
     72 
     73 template<typename T, typename U>
     74 U X2<T, U>::static_member2; // expected-error{{no matching}}
     75 
     76 template void X2<int, float>::f(int &, float);
     77 template void X2<int, float>::f(int &, double); // expected-error{{does not refer}}
     78 template void X2<int, int*>::f(int&, int*); // expected-note{{instantiation}}
     79 
     80 template struct X2<int, float>::Inner;
     81 template struct X2<int, Incomplete>::Inner; // expected-note{{instantiation}}
     82 
     83 template int X2<int, float>::static_member1;
     84 template int* X2<int*, float>::static_member1; // expected-note{{instantiation}}
     85 template
     86   NonDefaultConstructible X2<NonDefaultConstructible, int>::static_member1;
     87 
     88 template
     89   NonDefaultConstructible X2<int, NonDefaultConstructible>::static_member2; // expected-note{{instantiation}}
     90