instantiate-member-template.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T>
  3. struct X0 {
  4. template<typename U> T f0(U);
  5. template<typename U> U& f1(T*, U); // expected-error{{pointer to a reference}} \
  6. // expected-note{{candidate}}
  7. };
  8. X0<int> x0i;
  9. X0<void> x0v;
  10. X0<int&> x0ir; // expected-note{{instantiation}}
  11. void test_X0(int *ip, double *dp) {
  12. X0<int> xi;
  13. int i1 = xi.f0(ip);
  14. double *&dpr = xi.f1(ip, dp);
  15. xi.f1(dp, dp); // expected-error{{no matching}}
  16. X0<void> xv;
  17. double *&dpr2 = xv.f1(ip, dp);
  18. }
  19. template<typename T>
  20. struct X1 {
  21. template<typename U>
  22. struct Inner0 {
  23. U x;
  24. T y; // expected-error{{void}}
  25. };
  26. template<typename U>
  27. struct Inner1 {
  28. U x; // expected-error{{void}}
  29. T y;
  30. };
  31. template<typename U>
  32. struct Inner2 {
  33. struct SuperInner {
  34. U z; // expected-error{{void}}
  35. };
  36. };
  37. template<typename U>
  38. struct Inner3 {
  39. void f0(T t, U u) { // expected-note{{passing argument to parameter 't' here}}
  40. (void)(t + u); // expected-error{{invalid operands}}
  41. }
  42. template<typename V>
  43. V f1(T t, U u, V) {
  44. return t + u; // expected-error{{cannot initialize return object}}
  45. }
  46. };
  47. template<typename U>
  48. struct Inner4;
  49. };
  50. template<typename T>
  51. template<typename U>
  52. struct X1<T>::Inner4 {
  53. template<typename V>
  54. V f2(T t, U u, V);
  55. static U value;
  56. };
  57. template<typename T>
  58. template<typename U>
  59. U X1<T>::Inner4<U>::value; // expected-error{{reference variable}}
  60. template<typename T>
  61. template<typename U>
  62. template<typename V>
  63. V X1<T>::Inner4<U>::f2(T t, U u, V) {
  64. return t + u; // expected-error{{cannot initialize return object}}
  65. }
  66. void test_X1(int *ip, int i, double *dp) {
  67. X1<void>::Inner0<int> *xvip; // okay
  68. X1<void>::Inner0<int> xvi; // expected-note{{instantiation}}
  69. X1<int>::Inner1<void> *xivp; // okay
  70. X1<int>::Inner1<void> xiv; // expected-note{{instantiation}}
  71. X1<int>::Inner2<void>::SuperInner *xisivp; // okay
  72. X1<int>::Inner2<void>::SuperInner xisiv; // expected-note{{instantiation}}
  73. X1<int*>::Inner3<int> id3;
  74. id3.f0(ip, i);
  75. id3.f0(dp, i); // expected-error{{cannot initialize a parameter of type 'int *' with an lvalue of type 'double *'}}
  76. id3.f1(ip, i, ip);
  77. id3.f1(ip, i, dp); // expected-note{{instantiation}}
  78. X1<int*>::Inner3<double*> id3b;
  79. id3b.f0(ip, dp); // expected-note{{instantiation}}
  80. X1<int*>::Inner4<int> id4;
  81. id4.f2(ip, i, dp); // expected-note{{instantiation}}
  82. X1<int*>::Inner4<int>::value = 17;
  83. i = X1<int*>::Inner4<int&>::value; // expected-note{{instantiation}}
  84. }
  85. template<typename T>
  86. struct X2 {
  87. template<T *Ptr> // expected-error{{pointer to a reference}}
  88. struct Inner;
  89. template<T Value> // expected-error{{cannot have type 'float'}}
  90. struct Inner2;
  91. };
  92. X2<int&> x2a; // expected-note{{instantiation}}
  93. X2<float> x2b; // expected-note{{instantiation}}
  94. namespace N0 {
  95. template<typename T>
  96. struct X0 { };
  97. struct X1 {
  98. template<typename T> void f(X0<T>& vals) { g(vals); }
  99. template<typename T> void g(X0<T>& vals) { }
  100. };
  101. void test(X1 x1, X0<int> x0i, X0<long> x0l) {
  102. x1.f(x0i);
  103. x1.f(x0l);
  104. }
  105. }
  106. namespace PR6239 {
  107. template <typename T>
  108. struct X0 {
  109. class type {
  110. typedef T E;
  111. template <E e> // subsitute T for E and bug goes away
  112. struct sfinae { };
  113. template <class U>
  114. typename sfinae<&U::operator=>::type test(int);
  115. };
  116. };
  117. template <typename T>
  118. struct X1 {
  119. typedef T E;
  120. template <E e> // subsitute T for E and bug goes away
  121. struct sfinae { };
  122. template <class U>
  123. typename sfinae<&U::operator=>::type test(int);
  124. };
  125. }
  126. namespace PR7587 {
  127. template<typename> class X0;
  128. template<typename> struct X1;
  129. template<typename> class X2;
  130. template<typename T> class X3
  131. {
  132. template<
  133. template<typename> class TT,
  134. typename U = typename X1<T>::type
  135. >
  136. struct Inner {
  137. typedef X2<TT<typename X1<T>::type> > Type;
  138. };
  139. const typename Inner<X0>::Type minCoeff() const;
  140. };
  141. template<typename T> class X3<T*>
  142. {
  143. template<
  144. template<typename> class TT,
  145. typename U = typename X1<T>::type
  146. >
  147. struct Inner {
  148. typedef X2<TT<typename X1<T>::type> > Type;
  149. };
  150. const typename Inner<X0>::Type minCoeff() const;
  151. };
  152. }
  153. namespace PR7669 {
  154. template<class> struct X {
  155. template<class> struct Y {
  156. template<int,class> struct Z;
  157. template<int Dummy> struct Z<Dummy,int> {};
  158. };
  159. };
  160. void a()
  161. {
  162. X<int>::Y<int>::Z<0,int>();
  163. }
  164. }
  165. namespace PR8489 {
  166. template <typename CT>
  167. class C {
  168. template<typename FT>
  169. void F() {} // expected-note{{FT}}
  170. };
  171. void f() {
  172. C<int> c;
  173. c.F(); // expected-error{{no matching member function}}
  174. }
  175. }
  176. namespace rdar8986308 {
  177. template <bool> struct __static_assert_test;
  178. template <> struct __static_assert_test<true> {};
  179. template <unsigned> struct __static_assert_check {};
  180. namespace std {
  181. template <class _Tp, class _Up>
  182. struct __has_rebind
  183. {
  184. private:
  185. struct __two {char _; char __;};
  186. template <class _Xp> static __two __test(...);
  187. template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
  188. public:
  189. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  190. };
  191. }
  192. template <class T> struct B1 {};
  193. template <class T>
  194. struct B
  195. {
  196. template <class U> struct rebind {typedef B1<U> other;};
  197. };
  198. template <class T, class U> struct D1 {};
  199. template <class T, class U>
  200. struct D
  201. {
  202. template <class V> struct rebind {typedef D1<V, U> other;};
  203. };
  204. int main()
  205. {
  206. typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<B<int>, double>::value))>)> __t64;
  207. typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<D<char, int>, double>::value))>)> __t64;
  208. }
  209. }