libcxx

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

max.pass.cpp (1894B)


      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 // test numeric_limits
     11 
     12 // max()
     13 
     14 #include <limits>
     15 #include <climits>
     16 #include <cwchar>
     17 #include <cfloat>
     18 #include <cassert>
     19 
     20 #include "test_macros.h"
     21 
     22 template <class T>
     23 void
     24 test(T expected)
     25 {
     26     assert(std::numeric_limits<T>::max() == expected);
     27     assert(std::numeric_limits<T>::is_bounded);
     28     assert(std::numeric_limits<const T>::max() == expected);
     29     assert(std::numeric_limits<const T>::is_bounded);
     30     assert(std::numeric_limits<volatile T>::max() == expected);
     31     assert(std::numeric_limits<volatile T>::is_bounded);
     32     assert(std::numeric_limits<const volatile T>::max() == expected);
     33     assert(std::numeric_limits<const volatile T>::is_bounded);
     34 }
     35 
     36 int main()
     37 {
     38     test<bool>(true);
     39     test<char>(CHAR_MAX);
     40     test<signed char>(SCHAR_MAX);
     41     test<unsigned char>(UCHAR_MAX);
     42     test<wchar_t>(WCHAR_MAX);
     43 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
     44     test<char8_t>(UCHAR_MAX); // ??
     45 #endif
     46 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
     47     test<char16_t>(USHRT_MAX);
     48     test<char32_t>(UINT_MAX);
     49 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
     50     test<short>(SHRT_MAX);
     51     test<unsigned short>(USHRT_MAX);
     52     test<int>(INT_MAX);
     53     test<unsigned int>(UINT_MAX);
     54     test<long>(LONG_MAX);
     55     test<unsigned long>(ULONG_MAX);
     56     test<long long>(LLONG_MAX);
     57     test<unsigned long long>(ULLONG_MAX);
     58 #ifndef _LIBCPP_HAS_NO_INT128
     59     test<__int128_t>(__int128_t(__uint128_t(-1)/2));
     60     test<__uint128_t>(__uint128_t(-1));
     61 #endif
     62     test<float>(FLT_MAX);
     63     test<double>(DBL_MAX);
     64     test<long double>(LDBL_MAX);
     65 }