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