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