1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // test <ctime> 10 11 #include <ctime> 12 #include <type_traits> 13 #include "test_macros.h" 14 15 #ifndef NULL 16 #error NULL not defined 17 #endif 18 19 #ifndef CLOCKS_PER_SEC 20 #error CLOCKS_PER_SEC not defined 21 #endif 22 23 #if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET) 24 #ifndef TIME_UTC 25 #error TIME_UTC not defined 26 #endif 27 #endif 28 29 int main(int, char**) 30 { 31 std::clock_t c = 0; 32 std::size_t s = 0; 33 std::time_t t = 0; 34 std::tm tm = {}; 35 #if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET) 36 std::timespec tmspec = {}; 37 ((void)tmspec); // Prevent unused warning 38 #endif 39 ((void)c); // Prevent unused warning 40 ((void)s); // Prevent unused warning 41 ((void)t); // Prevent unused warning 42 ((void)tm); // Prevent unused warning 43 static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); 44 static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); 45 static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); 46 static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); 47 #if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET) 48 static_assert((std::is_same<decltype(std::timespec_get(nullptr, 0)), int>::value), ""); 49 #endif 50 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS 51 static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); 52 static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); 53 static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), ""); 54 static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), ""); 55 #endif 56 char* c1 = 0; 57 const char* c2 = 0; 58 ((void)c1); // Prevent unused warning 59 ((void)c2); // Prevent unused warning 60 static_assert((std::is_same<decltype(std::strftime(c1,s,c2,&tm)), std::size_t>::value), ""); 61 62 return 0; 63 } 64