temp_class_spec.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T>
  3. struct is_pointer {
  4. static const bool value = false;
  5. };
  6. template<typename T>
  7. struct is_pointer<T*> {
  8. static const bool value = true;
  9. };
  10. template<typename T>
  11. struct is_pointer<const T*> {
  12. static const bool value = true;
  13. };
  14. int array0[is_pointer<int>::value? -1 : 1];
  15. int array1[is_pointer<int*>::value? 1 : -1];
  16. int array2[is_pointer<const int*>::value? 1 : -1];
  17. template<typename T>
  18. struct is_lvalue_reference {
  19. static const bool value = false;
  20. };
  21. template<typename T>
  22. struct is_lvalue_reference<T&> {
  23. static const bool value = true;
  24. };
  25. int lvalue_ref0[is_lvalue_reference<int>::value? -1 : 1];
  26. int lvalue_ref1[is_lvalue_reference<const int&>::value? 1 : -1];
  27. template<typename T>
  28. struct is_const {
  29. static const bool value = false;
  30. };
  31. template<typename T>
  32. struct is_const<const T> {
  33. static const bool value = true;
  34. };
  35. int is_const0[is_const<int>::value? -1 : 1];
  36. int is_const1[is_const<const int>::value? 1 : -1];
  37. int is_const2[is_const<const volatile int>::value? 1 : -1];
  38. int is_const3[is_const<const int [3]>::value? 1 : -1];
  39. int is_const4[is_const<const volatile int[3]>::value? 1 : -1];
  40. int is_const5[is_const<volatile int[3]>::value? -1 : 1];
  41. template<typename T>
  42. struct is_volatile {
  43. static const bool value = false;
  44. };
  45. template<typename T>
  46. struct is_volatile<volatile T> {
  47. static const bool value = true;
  48. };
  49. int is_volatile0[is_volatile<int>::value? -1 : 1];
  50. int is_volatile1[is_volatile<volatile int>::value? 1 : -1];
  51. int is_volatile2[is_volatile<const volatile int>::value? 1 : -1];
  52. int is_volatile3[is_volatile<volatile char[3]>::value? 1 : -1];
  53. template<typename T, typename U>
  54. struct is_same {
  55. static const bool value = false;
  56. };
  57. template<typename T>
  58. struct is_same<T, T> {
  59. static const bool value = true;
  60. };
  61. typedef int INT;
  62. typedef INT* int_ptr;
  63. int is_same0[is_same<int, int>::value? 1 : -1];
  64. int is_same1[is_same<int, INT>::value? 1 : -1];
  65. int is_same2[is_same<const int, int>::value? -1 : 1];
  66. int is_same3[is_same<int_ptr, int>::value? -1 : 1];
  67. template<typename T>
  68. struct remove_reference {
  69. typedef T type;
  70. };
  71. template<typename T>
  72. struct remove_reference<T&> {
  73. typedef T type;
  74. };
  75. int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1];
  76. int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1];
  77. template<typename T>
  78. struct remove_const {
  79. typedef T type;
  80. };
  81. template<typename T>
  82. struct remove_const<const T> {
  83. typedef T type;
  84. };
  85. int remove_const0[is_same<remove_const<const int>::type, int>::value? 1 : -1];
  86. int remove_const1[is_same<remove_const<const int[3]>::type, int[3]>::value? 1 : -1];
  87. template<typename T>
  88. struct is_incomplete_array {
  89. static const bool value = false;
  90. };
  91. template<typename T>
  92. struct is_incomplete_array<T[]> {
  93. static const bool value = true;
  94. };
  95. int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1];
  96. int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1];
  97. int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1];
  98. int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1];
  99. template<typename T>
  100. struct is_array_with_4_elements {
  101. static const bool value = false;
  102. };
  103. template<typename T>
  104. struct is_array_with_4_elements<T[4]> {
  105. static const bool value = true;
  106. };
  107. int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1];
  108. int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1];
  109. int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1];
  110. int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1];
  111. template<typename T>
  112. struct get_array_size;
  113. template<typename T, unsigned N>
  114. struct get_array_size<T[N]> {
  115. static const unsigned value = N;
  116. };
  117. int array_size0[get_array_size<int[12]>::value == 12? 1 : -1];
  118. template<typename T>
  119. struct remove_extent {
  120. typedef T type;
  121. };
  122. template<typename T>
  123. struct remove_extent<T[]> {
  124. typedef T type;
  125. };
  126. template<typename T, unsigned N>
  127. struct remove_extent<T[N]> {
  128. typedef T type;
  129. };
  130. int remove_extent0[is_same<remove_extent<int[][5]>::type, int[5]>::value? 1 : -1];
  131. int remove_extent1[is_same<remove_extent<const int[][5]>::type, const int[5]>::value? 1 : -1];
  132. template<typename T>
  133. struct is_unary_function {
  134. static const bool value = false;
  135. };
  136. template<typename T, typename U>
  137. struct is_unary_function<T (*)(U)> {
  138. static const bool value = true;
  139. };
  140. int is_unary_function0[is_unary_function<int>::value ? -1 : 1];
  141. int is_unary_function1[is_unary_function<int (*)()>::value ? -1 : 1];
  142. int is_unary_function2[is_unary_function<int (*)(int, bool)>::value ? -1 : 1];
  143. int is_unary_function3[is_unary_function<int (*)(bool)>::value ? 1 : -1];
  144. int is_unary_function4[is_unary_function<int (*)(int)>::value ? 1 : -1];
  145. template<typename T>
  146. struct is_unary_function_with_same_return_type_as_argument_type {
  147. static const bool value = false;
  148. };
  149. template<typename T>
  150. struct is_unary_function_with_same_return_type_as_argument_type<T (*)(T)> {
  151. static const bool value = true;
  152. };
  153. int is_unary_function5[is_unary_function_with_same_return_type_as_argument_type<int>::value ? -1 : 1];
  154. int is_unary_function6[is_unary_function_with_same_return_type_as_argument_type<int (*)()>::value ? -1 : 1];
  155. int is_unary_function7[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, bool)>::value ? -1 : 1];
  156. int is_unary_function8[is_unary_function_with_same_return_type_as_argument_type<int (*)(bool)>::value ? -1 : 1];
  157. int is_unary_function9[is_unary_function_with_same_return_type_as_argument_type<int (*)(int)>::value ? 1 : -1];
  158. int is_unary_function10[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, ...)>::value ? -1 : 1];
  159. int is_unary_function11[is_unary_function_with_same_return_type_as_argument_type<int (* const)(int)>::value ? -1 : 1];
  160. template<typename T>
  161. struct is_binary_function {
  162. static const bool value = false;
  163. };
  164. template<typename R, typename T1, typename T2>
  165. struct is_binary_function<R(T1, T2)> {
  166. static const bool value = true;
  167. };
  168. int is_binary_function0[is_binary_function<int(float, double)>::value? 1 : -1];
  169. template<typename T>
  170. struct is_member_pointer {
  171. static const bool value = false;
  172. };
  173. template<typename T, typename Class>
  174. struct is_member_pointer<T Class::*> {
  175. static const bool value = true;
  176. };
  177. struct X { };
  178. int is_member_pointer0[is_member_pointer<int X::*>::value? 1 : -1];
  179. int is_member_pointer1[is_member_pointer<const int X::*>::value? 1 : -1];
  180. int is_member_pointer2[is_member_pointer<int (X::*)()>::value? 1 : -1];
  181. int is_member_pointer3[is_member_pointer<int (X::*)(int) const>::value? 1 : -1];
  182. int is_member_pointer4[is_member_pointer<int (X::**)(int) const>::value? -1 : 1];
  183. int is_member_pointer5[is_member_pointer<int>::value? -1 : 1];
  184. template<typename T>
  185. struct is_member_function_pointer {
  186. static const bool value = false;
  187. };
  188. template<typename T, typename Class>
  189. struct is_member_function_pointer<T (Class::*)()> {
  190. static const bool value = true;
  191. };
  192. template<typename T, typename Class>
  193. struct is_member_function_pointer<T (Class::*)() const> {
  194. static const bool value = true;
  195. };
  196. template<typename T, typename Class>
  197. struct is_member_function_pointer<T (Class::*)() volatile> {
  198. static const bool value = true;
  199. };
  200. template<typename T, typename Class>
  201. struct is_member_function_pointer<T (Class::*)() const volatile> {
  202. static const bool value = true;
  203. };
  204. template<typename T, typename Class, typename A1>
  205. struct is_member_function_pointer<T (Class::*)(A1)> {
  206. static const bool value = true;
  207. };
  208. template<typename T, typename Class, typename A1>
  209. struct is_member_function_pointer<T (Class::*)(A1) const> {
  210. static const bool value = true;
  211. };
  212. template<typename T, typename Class, typename A1>
  213. struct is_member_function_pointer<T (Class::*)(A1) volatile> {
  214. static const bool value = true;
  215. };
  216. template<typename T, typename Class, typename A1>
  217. struct is_member_function_pointer<T (Class::*)(A1) const volatile> {
  218. static const bool value = true;
  219. };
  220. int is_member_function_pointer0[
  221. is_member_function_pointer<int X::*>::value? -1 : 1];
  222. int is_member_function_pointer1[
  223. is_member_function_pointer<int (X::*)()>::value? 1 : -1];
  224. int is_member_function_pointer2[
  225. is_member_function_pointer<X (X::*)(X&)>::value? 1 : -1];
  226. int is_member_function_pointer3[
  227. is_member_function_pointer<int (X::*)() const>::value? 1 : -1];
  228. int is_member_function_pointer4[
  229. is_member_function_pointer<int (X::*)(float) const>::value? 1 : -1];
  230. // Test substitution of non-dependent arguments back into the template
  231. // argument list of the class template partial specialization.
  232. template<typename T, typename ValueType = T>
  233. struct is_nested_value_type_identity {
  234. static const bool value = false;
  235. };
  236. template<typename T>
  237. struct is_nested_value_type_identity<T, typename T::value_type> {
  238. static const bool value = true;
  239. };
  240. template<typename T>
  241. struct HasValueType {
  242. typedef T value_type;
  243. };
  244. struct HasIdentityValueType {
  245. typedef HasIdentityValueType value_type;
  246. };
  247. struct NoValueType { };
  248. int is_nested_value_type_identity0[
  249. is_nested_value_type_identity<HasValueType<int> >::value? -1 : 1];
  250. int is_nested_value_type_identity1[
  251. is_nested_value_type_identity<HasIdentityValueType>::value? 1 : -1];
  252. int is_nested_value_type_identity2[
  253. is_nested_value_type_identity<NoValueType>::value? -1 : 1];
  254. // C++ [temp.class.spec]p4:
  255. template<class T1, class T2, int I> class A { }; //#1
  256. template<class T, int I> class A<T, T*, I> { }; //#2
  257. template<class T1, class T2, int I> class A<T1*, T2, I> { }; //#3
  258. template<class T> class A<int, T*, 5> { }; //#4
  259. template<class T1, class T2, int I> class A<T1, T2*, I> { }; //#5
  260. // Redefinition of class template partial specializations
  261. template<typename T, T N, typename U> class A0;
  262. template<typename T, T N> class A0<T, N, int> { }; // expected-note{{here}}
  263. template<typename T, T N> class A0<T, N, int>;
  264. template<typename T, T N> class A0<T, N, int> { }; // expected-error{{redef}}
  265. namespace PR6025 {
  266. template< int N > struct A;
  267. namespace N
  268. {
  269. template< typename F >
  270. struct B;
  271. }
  272. template< typename Protect, typename Second >
  273. struct C;
  274. template <class T>
  275. struct C< T, A< N::B<T>::value > >
  276. {
  277. };
  278. }
  279. namespace PR6181 {
  280. template <class T>
  281. class a;
  282. class s;
  283. template <class U>
  284. class a<s> // expected-error{{partial specialization of 'a' does not use any of its template parameters}}
  285. {
  286. };
  287. }