stdlib_h.pass.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // test <stdlib.h>
  10. #include <stdlib.h>
  11. #include <type_traits>
  12. #include "test_macros.h"
  13. // As of 1/10/2015 clang emits a -Wnonnull warnings even if the warning occurs
  14. // in an unevaluated context. For this reason we manually suppress the warning.
  15. #if defined(__clang__)
  16. #pragma clang diagnostic ignored "-Wnonnull"
  17. #endif
  18. #ifdef abs
  19. #error abs is defined
  20. #endif
  21. #ifdef labs
  22. #error labs is defined
  23. #endif
  24. #ifdef llabs
  25. #error llabs is defined
  26. #endif
  27. #ifdef div
  28. #error div is defined
  29. #endif
  30. #ifdef ldiv
  31. #error ldiv is defined
  32. #endif
  33. #ifdef lldiv
  34. #error lldiv is defined
  35. #endif
  36. #ifndef EXIT_FAILURE
  37. #error EXIT_FAILURE not defined
  38. #endif
  39. #ifndef EXIT_SUCCESS
  40. #error EXIT_SUCCESS not defined
  41. #endif
  42. #ifndef MB_CUR_MAX
  43. #error MB_CUR_MAX not defined
  44. #endif
  45. #ifndef NULL
  46. #error NULL not defined
  47. #endif
  48. #ifndef RAND_MAX
  49. #error RAND_MAX not defined
  50. #endif
  51. int main()
  52. {
  53. size_t s = 0; ((void)s);
  54. div_t d; ((void)d);
  55. ldiv_t ld; ((void)ld);
  56. lldiv_t lld; ((void)lld);
  57. char** endptr = 0;
  58. static_assert((std::is_same<decltype(atof("")), double>::value), "");
  59. static_assert((std::is_same<decltype(atoi("")), int>::value), "");
  60. static_assert((std::is_same<decltype(atol("")), long>::value), "");
  61. static_assert((std::is_same<decltype(atoll("")), long long>::value), "");
  62. static_assert((std::is_same<decltype(getenv("")), char*>::value), "");
  63. static_assert((std::is_same<decltype(strtod("", endptr)), double>::value), "");
  64. static_assert((std::is_same<decltype(strtof("", endptr)), float>::value), "");
  65. static_assert((std::is_same<decltype(strtold("", endptr)), long double>::value), "");
  66. static_assert((std::is_same<decltype(strtol("", endptr,0)), long>::value), "");
  67. static_assert((std::is_same<decltype(strtoll("", endptr,0)), long long>::value), "");
  68. static_assert((std::is_same<decltype(strtoul("", endptr,0)), unsigned long>::value), "");
  69. static_assert((std::is_same<decltype(strtoull("", endptr,0)), unsigned long long>::value), "");
  70. static_assert((std::is_same<decltype(rand()), int>::value), "");
  71. static_assert((std::is_same<decltype(srand(0)), void>::value), "");
  72. // Microsoft does not implement aligned_alloc in their C library
  73. #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && !defined(_WIN32)
  74. static_assert((std::is_same<decltype(aligned_alloc(0,0)), void*>::value), "");
  75. #endif
  76. static_assert((std::is_same<decltype(calloc(0,0)), void*>::value), "");
  77. static_assert((std::is_same<decltype(free(0)), void>::value), "");
  78. static_assert((std::is_same<decltype(malloc(0)), void*>::value), "");
  79. static_assert((std::is_same<decltype(realloc(0,0)), void*>::value), "");
  80. static_assert((std::is_same<decltype(abort()), void>::value), "");
  81. static_assert((std::is_same<decltype(atexit(0)), int>::value), "");
  82. static_assert((std::is_same<decltype(exit(0)), void>::value), "");
  83. static_assert((std::is_same<decltype(_Exit(0)), void>::value), "");
  84. static_assert((std::is_same<decltype(getenv("")), char*>::value), "");
  85. static_assert((std::is_same<decltype(system("")), int>::value), "");
  86. static_assert((std::is_same<decltype(bsearch(0,0,0,0,0)), void*>::value), "");
  87. static_assert((std::is_same<decltype(qsort(0,0,0,0)), void>::value), "");
  88. static_assert((std::is_same<decltype(abs(0)), int>::value), "");
  89. static_assert((std::is_same<decltype(labs((long)0)), long>::value), "");
  90. static_assert((std::is_same<decltype(llabs((long long)0)), long long>::value), "");
  91. static_assert((std::is_same<decltype(div(0,0)), div_t>::value), "");
  92. static_assert((std::is_same<decltype(ldiv(0L,0L)), ldiv_t>::value), "");
  93. static_assert((std::is_same<decltype(lldiv(0LL,0LL)), lldiv_t>::value), "");
  94. wchar_t* pw = 0;
  95. const wchar_t* pwc = 0;
  96. char* pc = 0;
  97. static_assert((std::is_same<decltype(mblen("",0)), int>::value), "");
  98. static_assert((std::is_same<decltype(mbtowc(pw,"",0)), int>::value), "");
  99. static_assert((std::is_same<decltype(wctomb(pc,L' ')), int>::value), "");
  100. static_assert((std::is_same<decltype(mbstowcs(pw,"",0)), size_t>::value), "");
  101. static_assert((std::is_same<decltype(wcstombs(pc,pwc,0)), size_t>::value), "");
  102. }