libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

ctime.pass.cpp (2184B)


      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 
     10 #include <ctime>
     11 #include <type_traits>
     12 
     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_C11_FEATURES)
     24 #ifndef TIME_UTC
     25 #error TIME_UTC not defined
     26 #endif
     27 #endif
     28 
     29 #if defined(__GNUC__)
     30 #pragma GCC diagnostic ignored "-Wformat-zero-length"
     31 #endif
     32 
     33 int main()
     34 {
     35     std::clock_t c = 0;
     36     std::size_t s = 0;
     37     std::time_t t = 0;
     38     std::tm tm = {};
     39     char str[3];
     40     ((void)c); // Prevent unused warning
     41     ((void)s); // Prevent unused warning
     42     ((void)t); // Prevent unused warning
     43     ((void)tm); // Prevent unused warning
     44     ((void)str); // Prevent unused warning
     45 #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
     46     std::timespec tmspec = {};
     47     ((void)tmspec); // Prevent unused warning
     48 #endif
     49 
     50     static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
     51     static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
     52     static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
     53     static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), "");
     54 #if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
     55     static_assert((std::is_same<decltype(std::timespec_get(nullptr, 0)), int>::value), "");
     56 #endif
     57 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
     58     static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), "");
     59     static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), "");
     60     static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), "");
     61     static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), "");
     62 #endif
     63     static_assert((std::is_same<decltype(std::strftime(str,s,"",&tm)), std::size_t>::value), "");
     64 }