ctime.pass.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <ctime>
  10. #include <ctime>
  11. #include <type_traits>
  12. #ifndef NULL
  13. #error NULL not defined
  14. #endif
  15. #ifndef CLOCKS_PER_SEC
  16. #error CLOCKS_PER_SEC not defined
  17. #endif
  18. int main()
  19. {
  20. std::clock_t c = 0;
  21. std::size_t s = 0;
  22. std::time_t t = 0;
  23. std::tm tm = {0};
  24. ((void)c); // Prevent unused warning
  25. ((void)s); // Prevent unused warning
  26. ((void)t); // Prevent unused warning
  27. ((void)tm); // Prevent unused warning
  28. static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
  29. static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
  30. static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
  31. static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), "");
  32. #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
  33. static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), "");
  34. static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), "");
  35. static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), "");
  36. static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), "");
  37. #endif
  38. char* c1 = 0;
  39. const char* c2 = 0;
  40. ((void)c1); // Prevent unused warning
  41. ((void)c2); // Prevent unused warning
  42. static_assert((std::is_same<decltype(std::strftime(c1,s,c2,&tm)), std::size_t>::value), "");
  43. }