current-instantiation.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // This test concerns the identity of dependent types within the
  3. // canonical type system, specifically focusing on the difference
  4. // between members of the current instantiation and members of an
  5. // unknown specialization. This considers C++ [temp.type], which
  6. // specifies type equivalence within a template, and C++0x
  7. // [temp.dep.type], which defines what it means to be a member of the
  8. // current instantiation.
  9. template<typename T, typename U>
  10. struct X0 {
  11. typedef T T_type;
  12. typedef U U_type;
  13. void f0(T&); // expected-note{{previous}}
  14. void f0(typename X0::U_type&);
  15. void f0(typename X0::T_type&); // expected-error{{redecl}}
  16. void f1(T&); // expected-note{{previous}}
  17. void f1(typename X0::U_type&);
  18. void f1(typename X0<T, U>::T_type&); // expected-error{{redecl}}
  19. void f2(T&); // expected-note{{previous}}
  20. void f2(typename X0::U_type&);
  21. void f2(typename X0<T_type, U_type>::T_type&); // expected-error{{redecl}}
  22. void f3(T&); // expected-note{{previous}}
  23. void f3(typename X0::U_type&);
  24. void f3(typename ::X0<T_type, U_type>::T_type&); // expected-error{{redecl}}
  25. struct X1 {
  26. typedef T my_T_type;
  27. void g0(T&); // expected-note{{previous}}
  28. void g0(typename X0::U_type&);
  29. void g0(typename X0::T_type&); // expected-error{{redecl}}
  30. void g1(T&); // expected-note{{previous}}
  31. void g1(typename X0::U_type&);
  32. void g1(typename X0<T, U>::T_type&); // expected-error{{redecl}}
  33. void g2(T&); // expected-note{{previous}}
  34. void g2(typename X0::U_type&);
  35. void g2(typename X0<T_type, U_type>::T_type&); // expected-error{{redecl}}
  36. void g3(T&); // expected-note{{previous}}
  37. void g3(typename X0::U_type&);
  38. void g3(typename ::X0<T_type, U_type>::T_type&); // expected-error{{redecl}}
  39. void g4(T&); // expected-note{{previous}}
  40. void g4(typename X0::U_type&);
  41. void g4(typename X1::my_T_type&); // expected-error{{redecl}}
  42. void g5(T&); // expected-note{{previous}}
  43. void g5(typename X0::U_type&);
  44. void g5(typename X0::X1::my_T_type&); // expected-error{{redecl}}
  45. void g6(T&); // expected-note{{previous}}
  46. void g6(typename X0::U_type&);
  47. void g6(typename X0<T, U>::X1::my_T_type&); // expected-error{{redecl}}
  48. void g7(T&); // expected-note{{previous}}
  49. void g7(typename X0::U_type&);
  50. void g7(typename ::X0<typename X1::my_T_type, U_type>::X1::my_T_type&); // expected-error{{redecl}}
  51. void g8(T&); // expected-note{{previous}}
  52. void g8(typename X0<U, T_type>::T_type&);
  53. void g8(typename ::X0<typename X0<T_type, U>::X1::my_T_type, U_type>::X1::my_T_type&); // expected-error{{redecl}}
  54. };
  55. };
  56. template<typename T, typename U>
  57. struct X0<T*, U*> {
  58. typedef T T_type;
  59. typedef U U_type;
  60. typedef T* Tptr;
  61. typedef U* Uptr;
  62. void f0(T&); // expected-note{{previous}}
  63. void f0(typename X0::U_type&);
  64. void f0(typename X0::T_type&); // expected-error{{redecl}}
  65. void f1(T&); // expected-note{{previous}}
  66. void f1(typename X0::U_type&);
  67. void f1(typename X0<T*, U*>::T_type&); // expected-error{{redecl}}
  68. void f2(T&); // expected-note{{previous}}
  69. void f2(typename X0::U_type&);
  70. void f2(typename X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}}
  71. void f3(T&); // expected-note{{previous}}
  72. void f3(typename X0::U_type&);
  73. void f3(typename ::X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}}
  74. void f4(T&); // expected-note{{previous}}
  75. void f4(typename X0::U_type&);
  76. void f4(typename ::X0<Tptr, Uptr>::T_type&); // expected-error{{redecl}}
  77. void f5(X0*); // expected-note{{previous}}
  78. void f5(::X0<T, U>*);
  79. void f5(::X0<T*, U*>*); // expected-error{{redecl}}
  80. struct X2 {
  81. typedef T my_T_type;
  82. void g0(T&); // expected-note{{previous}}
  83. void g0(typename X0::U_type&);
  84. void g0(typename X0::T_type&); // expected-error{{redecl}}
  85. void g1(T&); // expected-note{{previous}}
  86. void g1(typename X0::U_type&);
  87. void g1(typename X0<T*, U*>::T_type&); // expected-error{{redecl}}
  88. void g2(T&); // expected-note{{previous}}
  89. void g2(typename X0::U_type&);
  90. void g2(typename X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}}
  91. void g3(T&); // expected-note{{previous}}
  92. void g3(typename X0::U_type&);
  93. void g3(typename ::X0<T_type*, U_type*>::T_type&); // expected-error{{redecl}}
  94. void g4(T&); // expected-note{{previous}}
  95. void g4(typename X0::U_type&);
  96. void g4(typename X2::my_T_type&); // expected-error{{redecl}}
  97. void g5(T&); // expected-note{{previous}}
  98. void g5(typename X0::U_type&);
  99. void g5(typename X0::X2::my_T_type&); // expected-error{{redecl}}
  100. void g6(T&); // expected-note{{previous}}
  101. void g6(typename X0::U_type&);
  102. void g6(typename X0<T*, U*>::X2::my_T_type&); // expected-error{{redecl}}
  103. void g7(T&); // expected-note{{previous}}
  104. void g7(typename X0::U_type&);
  105. void g7(typename ::X0<typename X2::my_T_type*, U_type*>::X2::my_T_type&); // expected-error{{redecl}}
  106. void g8(T&); // expected-note{{previous}}
  107. void g8(typename X0<U, T_type>::T_type&);
  108. void g8(typename ::X0<typename X0<T_type*, U*>::X2::my_T_type*, U_type*>::X2::my_T_type&); // expected-error{{redecl}}
  109. };
  110. };
  111. template<typename T>
  112. struct X1 {
  113. static int *a;
  114. void f(float *b) {
  115. X1<T>::a = b; // expected-error{{incompatible}}
  116. X1<T*>::a = b;
  117. }
  118. };
  119. namespace ConstantInCurrentInstantiation {
  120. template<typename T>
  121. struct X {
  122. static const int value = 2;
  123. static int array[value];
  124. };
  125. template<typename T> const int X<T>::value;
  126. template<typename T>
  127. int X<T>::array[X<T>::value] = { 1, 2 };
  128. }
  129. namespace Expressions {
  130. template <bool b>
  131. struct Bool {
  132. enum anonymous_enum { value = b };
  133. };
  134. struct True : public Bool<true> {};
  135. struct False : public Bool<false> {};
  136. template <typename T1, typename T2>
  137. struct Is_Same : public False {};
  138. template <typename T>
  139. struct Is_Same<T, T> : public True {};
  140. template <bool b, typename T = void>
  141. struct Enable_If {};
  142. template <typename T>
  143. struct Enable_If<true, T> {
  144. typedef T type;
  145. };
  146. template <typename T>
  147. class Class {
  148. public:
  149. template <typename U>
  150. typename Enable_If<Is_Same<U, Class>::value, void>::type
  151. foo();
  152. };
  153. template <typename T>
  154. template <typename U>
  155. typename Enable_If<Is_Same<U, Class<T> >::value, void>::type
  156. Class<T>::foo() {}
  157. }
  158. namespace PR9255 {
  159. template<typename T>
  160. class X0 {
  161. public:
  162. class Inner1;
  163. class Inner2 {
  164. public:
  165. void f()
  166. {
  167. Inner1::f.g();
  168. }
  169. };
  170. };
  171. }
  172. namespace rdar10194295 {
  173. template<typename XT>
  174. class X {
  175. public:
  176. enum Enum { Yes, No };
  177. template<Enum> void foo();
  178. template<Enum> class Inner;
  179. };
  180. template<typename XT>
  181. template<typename X<XT>::Enum>
  182. void X<XT>::foo()
  183. {
  184. }
  185. template<typename XT>
  186. template<typename X<XT>::Enum>
  187. class X<XT>::Inner { };
  188. }
  189. namespace RebuildDependentScopeDeclRefExpr {
  190. template<int> struct N {};
  191. template<typename T> struct X {
  192. static const int thing = 0;
  193. N<thing> data();
  194. N<thing> foo();
  195. };
  196. template<typename T> N<X<T>::thing> X<T>::data() {}
  197. // FIXME: We should issue a typo-correction here.
  198. template<typename T> N<X<T>::think> X<T>::foo() {} // expected-error {{no member named 'think' in 'X<T>'}}
  199. }