extern-templates.cpp 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T>
  3. class X0 {
  4. public:
  5. void f(T t);
  6. struct Inner {
  7. void g(T t);
  8. };
  9. };
  10. template<typename T>
  11. void X0<T>::f(T t) {
  12. t = 17; // expected-error{{incompatible}}
  13. }
  14. extern template class X0<int>;
  15. extern template class X0<int*>;
  16. template<typename T>
  17. void X0<T>::Inner::g(T t) {
  18. t = 17; // expected-error{{incompatible}}
  19. }
  20. void test_intptr(X0<int*> xi, X0<int*>::Inner xii) {
  21. xi.f(0);
  22. xii.g(0);
  23. }
  24. extern template class X0<long*>;
  25. void test_longptr(X0<long*> xl, X0<long*>::Inner xli) {
  26. xl.f(0);
  27. xli.g(0);
  28. }
  29. template class X0<long*>; // expected-note 2{{instantiation}}
  30. template<typename T>
  31. class X1 {
  32. public:
  33. void f(T t) { t += 2; }
  34. void g(T t);
  35. };
  36. template<typename T>
  37. void X1<T>::g(T t) {
  38. t += 2;
  39. }
  40. extern template class X1<void*>;
  41. void g_X1(X1<void*> x1, void *ptr) {
  42. x1.g(ptr);
  43. }
  44. extern template void X1<const void*>::g(const void*);
  45. void g_X1_2(X1<const void *> x1, const void *ptr) {
  46. x1.g(ptr);
  47. }