kwsysPlatformCxxTests.cxx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // Setup for tests that use result of stl namespace test.
  2. #if defined(KWSYS_STL_HAVE_STD)
  3. # if KWSYS_STL_HAVE_STD
  4. # define kwsys_stl std
  5. # else
  6. # define kwsys_stl
  7. # endif
  8. #endif
  9. #ifdef TEST_KWSYS_STL_HAVE_STD
  10. #include <list>
  11. void f(std::list<int>*) {}
  12. int main() { return 0; }
  13. #endif
  14. #ifdef TEST_KWSYS_IOS_USE_ANSI
  15. #include <iosfwd>
  16. int main() { return 0; }
  17. #endif
  18. #ifdef TEST_KWSYS_IOS_HAVE_STD
  19. #include <iosfwd>
  20. void f(std::ostream*) {}
  21. int main() { return 0; }
  22. #endif
  23. #ifdef TEST_KWSYS_IOS_USE_SSTREAM
  24. #include <sstream>
  25. int main()
  26. {
  27. std::ostringstream ostr;
  28. ostr << "hello";
  29. if(ostr.str().size() == 5)
  30. {
  31. return 0;
  32. }
  33. return -1;
  34. }
  35. #endif
  36. #ifdef TEST_KWSYS_IOS_USE_STRSTREAM_H
  37. #include <strstream.h>
  38. int main() { return 0; }
  39. #endif
  40. #ifdef TEST_KWSYS_IOS_USE_STRSTREA_H
  41. #include <strstrea.h>
  42. int main() { return 0; }
  43. #endif
  44. #ifdef TEST_KWSYS_STL_STRING_HAVE_OSTREAM
  45. # include <iostream.h>
  46. # include <string>
  47. void f(ostream& os, const kwsys_stl::string& s) { os << s; }
  48. int main() { return 0; }
  49. #endif
  50. #ifdef TEST_KWSYS_STL_STRING_HAVE_ISTREAM
  51. # include <iostream.h>
  52. # include <string>
  53. void f(istream& is, kwsys_stl::string& s) { is >> s; }
  54. int main() { return 0; }
  55. #endif
  56. #ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
  57. # include <string>
  58. bool f(const kwsys_stl::string& s) { return s != ""; }
  59. int main() { return 0; }
  60. #endif
  61. #ifdef TEST_KWSYS_CXX_HAS_CSTDDEF
  62. #include <cstddef>
  63. void f(size_t) {}
  64. int main() { return 0; }
  65. #endif
  66. #ifdef TEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
  67. template <class T> class A;
  68. template <class T> int f(A<T>&);
  69. template <class T> class A
  70. {
  71. public:
  72. // "friend int f<>(A<T>&)" would conform
  73. friend int f(A<T>&);
  74. private:
  75. int x;
  76. };
  77. template <class T> int f(A<T>& a) { return a.x = 0; }
  78. template int f(A<int>&);
  79. int main()
  80. {
  81. A<int> a;
  82. return f(a);
  83. }
  84. #endif
  85. #ifdef TEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES
  86. template <class U>
  87. class A
  88. {
  89. public:
  90. U u;
  91. A(): u(0) {}
  92. template <class V> V m(V* p) { return *p = u; }
  93. };
  94. int main()
  95. {
  96. A<short> a;
  97. int s = 1;
  98. return a.m(&s);
  99. }
  100. #endif
  101. #ifdef TEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION
  102. template <class T> struct A {};
  103. template <> struct A<int*>
  104. {
  105. static int f() { return 0; }
  106. };
  107. int main() { return A<int*>::f(); }
  108. #endif
  109. #ifdef TEST_KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
  110. namespace N
  111. {
  112. class A {};
  113. int f(A*) { return 0; }
  114. }
  115. void f(void*);
  116. int main()
  117. {
  118. N::A* a = 0;
  119. return f(a);
  120. }
  121. #endif
  122. #ifdef TEST_KWSYS_STL_HAS_ITERATOR_TRAITS
  123. #include <iterator>
  124. #include <list>
  125. void f(kwsys_stl::iterator_traits<kwsys_stl::list<int>::iterator>::iterator_category const&) {}
  126. int main() { return 0; }
  127. #endif
  128. #ifdef TEST_KWSYS_STL_HAS_ITERATOR_CATEGORY
  129. #include <iterator>
  130. #include <list>
  131. void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::iterator_category(x); }
  132. int main() { return 0; }
  133. #endif
  134. #ifdef TEST_KWSYS_STL_HAS___ITERATOR_CATEGORY
  135. #include <iterator>
  136. #include <list>
  137. void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::__iterator_category(x); }
  138. int main() { return 0; }
  139. #endif
  140. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
  141. #include <memory>
  142. template <class Alloc>
  143. void f(const Alloc&)
  144. {
  145. typedef typename Alloc::size_type alloc_size_type;
  146. }
  147. int main()
  148. {
  149. f(kwsys_stl::allocator<char>());
  150. return 0;
  151. }
  152. #endif
  153. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
  154. #include <memory>
  155. void f(kwsys_stl::allocator::size_type const&) {}
  156. int main() { return 0; }
  157. #endif
  158. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
  159. #include <memory>
  160. template <class T, class Alloc>
  161. void f(const T&, const Alloc&)
  162. {
  163. typedef typename Alloc::template rebind<T>::other alloc_type;
  164. }
  165. int main()
  166. {
  167. f(0, kwsys_stl::allocator<char>());
  168. return 0;
  169. }
  170. #endif
  171. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
  172. #include <memory>
  173. void f(kwsys_stl::allocator<char> const& a)
  174. {
  175. a.max_size(sizeof(int));
  176. }
  177. int main()
  178. {
  179. f(kwsys_stl::allocator<char>());
  180. return 0;
  181. }
  182. #endif
  183. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_OBJECTS
  184. #include <vector>
  185. void f(kwsys_stl::vector<int> const& v1)
  186. {
  187. kwsys_stl::vector<int>(1, 1, v1.get_allocator());
  188. }
  189. int main()
  190. {
  191. f(kwsys_stl::vector<int>());
  192. return 0;
  193. }
  194. #endif
  195. #ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
  196. #include <sys/types.h>
  197. #include <sys/stat.h>
  198. #include <unistd.h>
  199. int main()
  200. {
  201. struct stat stat1;
  202. (void)stat1.st_mtim.tv_sec;
  203. (void)stat1.st_mtim.tv_nsec;
  204. return 0;
  205. }
  206. #endif
  207. #ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
  208. void function(long**) {}
  209. int main()
  210. {
  211. __int64** p = 0;
  212. function(p);
  213. return 0;
  214. }
  215. #endif
  216. #ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
  217. void function(long long**) {}
  218. int main()
  219. {
  220. __int64** p = 0;
  221. function(p);
  222. return 0;
  223. }
  224. #endif
  225. #ifdef TEST_KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
  226. void function(double& l, unsigned __int64 const& r)
  227. {
  228. l = static_cast<double>(r);
  229. }
  230. int main()
  231. {
  232. double tTo = 0.0;
  233. unsigned __int64 tFrom = 0;
  234. function(tTo, tFrom);
  235. return 0;
  236. }
  237. #endif
  238. #ifdef TEST_KWSYS_CHAR_IS_SIGNED
  239. /* Return 1 for char signed and 0 for char unsigned. */
  240. int main()
  241. {
  242. unsigned char uc = 255;
  243. return (*reinterpret_cast<char*>(&uc) < 0)?1:0;
  244. }
  245. #endif
  246. #ifdef TEST_KWSYS_CXX_TYPE_INFO
  247. /* Collect fundamental type information and save it to a CMake script. */
  248. /* Include limits.h to get macros indicating long long and __int64.
  249. Note that certain compilers need special macros to define these
  250. macros in limits.h. */
  251. #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
  252. # define _MSC_EXTENSIONS
  253. #endif
  254. #if defined(__GNUC__) && __GNUC__ < 3
  255. # define _GNU_SOURCE
  256. #endif
  257. #include <limits.h>
  258. #include <stdio.h>
  259. #include <string.h>
  260. /* Due to shell differences and limitations of ADD_DEFINITIONS the
  261. KWSYS_CXX_TYPE_INFO_FILE macro will sometimes have double quotes
  262. and sometimes not. This macro will make sure the value is treated
  263. as a double-quoted string. */
  264. #define TO_STRING(x) TO_STRING0(x)
  265. #define TO_STRING0(x) TO_STRING1(x)
  266. #define TO_STRING1(x) #x
  267. void f() {}
  268. int main()
  269. {
  270. /* Construct the output file name. Some preprocessors will add an
  271. extra level of double quotes, so strip them. */
  272. char fbuf[] = TO_STRING(KWSYS_CXX_TYPE_INFO_FILE);
  273. char* fname = fbuf;
  274. if(fname[0] == '"')
  275. {
  276. ++fname;
  277. int len = static_cast<int>(strlen(fname));
  278. if(len > 0 && fname[len-1] == '"')
  279. {
  280. fname[len-1] = 0;
  281. }
  282. }
  283. /* Try to open the output file. */
  284. if(FILE* fout = fopen(fname, "w"))
  285. {
  286. /* Set the size of standard types. */
  287. fprintf(fout, "SET(KWSYS_SIZEOF_CHAR %d)\n", static_cast<int>(sizeof(char)));
  288. fprintf(fout, "SET(KWSYS_SIZEOF_SHORT %d)\n", static_cast<int>(sizeof(short)));
  289. fprintf(fout, "SET(KWSYS_SIZEOF_INT %d)\n", static_cast<int>(sizeof(int)));
  290. fprintf(fout, "SET(KWSYS_SIZEOF_LONG %d)\n", static_cast<int>(sizeof(long)));
  291. /* Set the size of some non-standard but common types. */
  292. /* Check for a limits.h macro for long long to see if the type exists. */
  293. #if defined(LLONG_MAX) || defined(LONG_LONG_MAX) || defined(LONGLONG_MAX)
  294. fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG %d)\n", static_cast<int>(sizeof(long long)));
  295. #else
  296. fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG 0) # No long long available.\n");
  297. #endif
  298. /* Check for a limits.h macro for __int64 to see if the type exists. */
  299. #if defined(_I64_MIN)
  300. fprintf(fout, "SET(KWSYS_SIZEOF___INT64 %d)\n", static_cast<int>(sizeof(__int64)));
  301. #else
  302. fprintf(fout, "SET(KWSYS_SIZEOF___INT64 0) # No __int64 available.\n");
  303. #endif
  304. /* Set the size of some pointer types. */
  305. fprintf(fout, "SET(KWSYS_SIZEOF_PDATA %d)\n", static_cast<int>(sizeof(void*)));
  306. fprintf(fout, "SET(KWSYS_SIZEOF_PFUNC %d)\n", static_cast<int>(sizeof(&f)));
  307. /* Set whether the native type "char" is signed or unsigned. */
  308. unsigned char uc = 255;
  309. fprintf(fout, "SET(KWSYS_CHAR_IS_SIGNED %d)\n",
  310. (*reinterpret_cast<char*>(&uc) < 0)?1:0);
  311. fclose(fout);
  312. return 0;
  313. }
  314. else
  315. {
  316. fprintf(stderr, "Failed to write fundamental type info to \"%s\".\n",
  317. fname);
  318. return 1;
  319. }
  320. }
  321. #endif