instantiate-complete.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s
  2. // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -verify %s
  3. // Tests various places where requiring a complete type involves
  4. // instantiation of that type.
  5. template<typename T>
  6. struct X {
  7. X(T);
  8. #ifdef MSABI
  9. // expected-error@+2{{data member instantiated with function type 'long (long)'}}
  10. #endif
  11. T f; // expected-error{{data member instantiated with function type 'float (int)'}} \
  12. // expected-error{{data member instantiated with function type 'int (int)'}} \
  13. // expected-error{{data member instantiated with function type 'char (char)'}} \
  14. // expected-error{{data member instantiated with function type 'short (short)'}} \
  15. // expected-error{{data member instantiated with function type 'float (float)'}}
  16. };
  17. X<int> f() { return 0; }
  18. struct XField {
  19. X<float(int)> xf; // expected-note{{in instantiation of template class 'X<float (int)>' requested here}}
  20. };
  21. void test_subscript(X<double> *ptr1, X<int(int)> *ptr2, int i) {
  22. (void)ptr1[i];
  23. (void)ptr2[i]; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}}
  24. }
  25. void test_arith(X<signed char> *ptr1, X<unsigned char> *ptr2,
  26. X<char(char)> *ptr3, X<short(short)> *ptr4) {
  27. (void)(ptr1 + 5);
  28. (void)(5 + ptr2);
  29. (void)(ptr3 + 5); // expected-note{{in instantiation of template class 'X<char (char)>' requested here}}
  30. (void)(5 + ptr4); // expected-note{{in instantiation of template class 'X<short (short)>' requested here}}
  31. }
  32. void test_new() {
  33. (void)new X<float>(0);
  34. (void)new X<float(float)>; // expected-note{{in instantiation of template class 'X<float (float)>' requested here}}
  35. }
  36. void test_memptr(X<long> *p1, long X<long>::*pm1,
  37. X<long(long)> *p2,
  38. #ifdef MSABI
  39. long (X<long(long)>::*pm2)(long)) { // expected-note{{in instantiation of template class 'X<long (long)>' requested here}}
  40. #else
  41. long (X<long(long)>::*pm2)(long)) {
  42. #endif
  43. (void)(p1->*pm1);
  44. }
  45. // Reference binding to a base
  46. template<typename T>
  47. struct X1 { };
  48. template<typename T>
  49. struct X2 : public T { };
  50. void refbind_base(X2<X1<int> > &x2) {
  51. X1<int> &x1 = x2;
  52. }
  53. // Enumerate constructors for user-defined conversion.
  54. template<typename T>
  55. struct X3 {
  56. X3(T);
  57. };
  58. void enum_constructors(X1<float> &x1) {
  59. X3<X1<float> > x3 = x1;
  60. }
  61. namespace PR6376 {
  62. template<typename T, typename U> struct W { };
  63. template<typename T>
  64. struct X {
  65. template<typename U>
  66. struct apply {
  67. typedef W<T, U> type;
  68. };
  69. };
  70. template<typename T, typename U>
  71. struct Y : public X<T>::template apply<U>::type { };
  72. template struct Y<int, float>;
  73. }
  74. namespace TemporaryObjectCopy {
  75. // Make sure we instantiate classes when we create a temporary copy.
  76. template<typename T>
  77. struct X {
  78. X(T);
  79. };
  80. template<typename T>
  81. void f(T t) {
  82. const X<int> &x = X<int>(t);
  83. }
  84. template void f(int);
  85. }
  86. namespace PR7080 {
  87. template <class T, class U>
  88. class X
  89. {
  90. typedef char true_t;
  91. class false_t { char dummy[2]; };
  92. static true_t dispatch(U);
  93. static false_t dispatch(...);
  94. static T trigger();
  95. public:
  96. enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
  97. };
  98. template <class T>
  99. class rv : public T
  100. { };
  101. bool x = X<int, rv<int>&>::value;
  102. }
  103. namespace pr7199 {
  104. template <class T> class A; // expected-note {{template is declared here}}
  105. template <class T> class B {
  106. class A<T>::C field; // expected-error {{implicit instantiation of undefined template 'pr7199::A<int>'}}
  107. };
  108. template class B<int>; // expected-note {{in instantiation}}
  109. }
  110. namespace PR8425 {
  111. template <typename T>
  112. class BaseT {};
  113. template <typename T>
  114. class DerivedT : public BaseT<T> {};
  115. template <typename T>
  116. class FromT {
  117. public:
  118. operator DerivedT<T>() const { return DerivedT<T>(); }
  119. };
  120. void test() {
  121. FromT<int> ft;
  122. BaseT<int> bt(ft);
  123. }
  124. }