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 // type_traits
11
12 // make_unsigned
13
14 #include <type_traits>
15
16 #include "test_macros.h"
17
18 enum Enum {zero, one_};
19
20 #if TEST_STD_VER >= 11
21 enum BigEnum : unsigned long long // MSVC's ABI doesn't follow the Standard
22 #else
23 enum BigEnum
24 #endif
25 {
26 bigzero,
27 big = 0xFFFFFFFFFFFFFFFFULL
28 };
29
30 #if !defined(_LIBCPP_HAS_NO_INT128) && !defined(_LIBCPP_HAS_NO_STRONG_ENUMS)
31 enum HugeEnum : __int128_t
32 {
33 hugezero
34 };
35 #endif
36
37 template <class T, class U>
test_make_unsigned()38 void test_make_unsigned()
39 {
40 static_assert((std::is_same<typename std::make_unsigned<T>::type, U>::value), "");
41 #if TEST_STD_VER > 11
42 static_assert((std::is_same<std::make_unsigned_t<T>, U>::value), "");
43 #endif
44 }
45
main()46 int main()
47 {
48 test_make_unsigned<signed char, unsigned char> ();
49 test_make_unsigned<unsigned char, unsigned char> ();
50 test_make_unsigned<char, unsigned char> ();
51 test_make_unsigned<short, unsigned short> ();
52 test_make_unsigned<unsigned short, unsigned short> ();
53 test_make_unsigned<int, unsigned int> ();
54 test_make_unsigned<unsigned int, unsigned int> ();
55 test_make_unsigned<long, unsigned long> ();
56 test_make_unsigned<unsigned long, unsigned long> ();
57 test_make_unsigned<long long, unsigned long long> ();
58 test_make_unsigned<unsigned long long, unsigned long long> ();
59 test_make_unsigned<wchar_t, std::conditional<sizeof(wchar_t) == 4, unsigned int, unsigned short>::type> ();
60 test_make_unsigned<const wchar_t, std::conditional<sizeof(wchar_t) == 4, const unsigned int, const unsigned short>::type> ();
61 test_make_unsigned<const Enum, std::conditional<sizeof(Enum) == sizeof(int), const unsigned int, const unsigned char>::type >();
62 test_make_unsigned<BigEnum,
63 std::conditional<sizeof(long) == 4, unsigned long long, unsigned long>::type> ();
64 #ifndef _LIBCPP_HAS_NO_INT128
65 test_make_unsigned<__int128_t, __uint128_t>();
66 test_make_unsigned<__uint128_t, __uint128_t>();
67 # ifndef _LIBCPP_HAS_NO_STRONG_ENUMS
68 test_make_unsigned<HugeEnum, __uint128_t>();
69 # endif
70 #endif
71 }
72