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_signed
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(_LIBCPP_HAS_NO_INT128) && !defined(_LIBCPP_HAS_NO_STRONG_ENUMS)
30 enum HugeEnum : __uint128_t
31 {
32     hugezero
33 };
34 #endif
35 
36 template <class T, class U>
test_make_signed()37 void test_make_signed()
38 {
39     ASSERT_SAME_TYPE(U, typename std::make_signed<T>::type);
40 #if TEST_STD_VER > 11
41     ASSERT_SAME_TYPE(U, std::make_signed_t<T>);
42 #endif
43 }
44 
main(int,char **)45 int main(int, char**)
46 {
47     test_make_signed< signed char, signed char >();
48     test_make_signed< unsigned char, signed char >();
49     test_make_signed< char, signed char >();
50     test_make_signed< short, signed short >();
51     test_make_signed< unsigned short, signed short >();
52     test_make_signed< int, signed int >();
53     test_make_signed< unsigned int, signed int >();
54     test_make_signed< long, signed long >();
55     test_make_signed< unsigned long, long >();
56     test_make_signed< long long, signed long long >();
57     test_make_signed< unsigned long long, signed long long >();
58     test_make_signed< wchar_t, std::conditional<sizeof(wchar_t) == 4, int, short>::type >();
59     test_make_signed< const wchar_t, std::conditional<sizeof(wchar_t) == 4, const int, const short>::type >();
60     test_make_signed< const Enum, std::conditional<sizeof(Enum) == sizeof(int), const int, const signed char>::type >();
61     test_make_signed< BigEnum, std::conditional<sizeof(long) == 4, long long, long>::type >();
62 #ifndef _LIBCPP_HAS_NO_INT128
63     test_make_signed< __int128_t, __int128_t >();
64     test_make_signed< __uint128_t, __int128_t >();
65 # ifndef _LIBCPP_HAS_NO_STRONG_ENUMS
66     test_make_signed< HugeEnum, __int128_t >();
67 # endif
68 #endif
69 
70   return 0;
71 }
72