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 // ::timespec_get is provided by the C library, but it's marked as 12 // unavailable until macOS 10.15 13 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}} 14 15 #include <ctime> 16 #include <type_traits> 17 #include "test_macros.h" 18 19 #ifndef NULL 20 #error NULL not defined 21 #endif 22 23 #ifndef CLOCKS_PER_SEC 24 #error CLOCKS_PER_SEC not defined 25 #endif 26 27 #if TEST_STD_VER > 14 28 #ifndef TIME_UTC 29 #error TIME_UTC not defined 30 #endif 31 #endif 32 33 int main(int, char**) 34 { 35 std::clock_t c = 0; 36 std::size_t s = 0; 37 std::time_t t = 0; 38 std::tm tm = {}; 39 #if TEST_STD_VER > 14 40 std::timespec tmspec = {}; 41 ((void)tmspec); // Prevent unused warning 42 #endif 43 ((void)c); // Prevent unused warning 44 ((void)s); // Prevent unused warning 45 ((void)t); // Prevent unused warning 46 ((void)tm); // Prevent unused warning 47 static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); 48 static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); 49 static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); 50 static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); 51 #if TEST_STD_VER > 14 52 static_assert((std::is_same<decltype(std::timespec_get(&tmspec, 0)), int>::value), ""); 53 #endif 54 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS 55 static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); 56 static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); 57 static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), ""); 58 static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), ""); 59 #endif 60 char* c1 = 0; 61 const char* c2 = 0; 62 ((void)c1); // Prevent unused warning 63 ((void)c2); // Prevent unused warning 64 static_assert((std::is_same<decltype(std::strftime(c1,s,c2,&tm)), std::size_t>::value), ""); 65 66 return 0; 67 } 68