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 | // is_unsigned |
12 | |
13 | #include <type_traits> |
14 | #include "test_macros.h" |
15 | |
16 | template <class T> |
17 | void test_is_unsigned() |
18 | { |
19 | static_assert( std::is_unsigned<T>::value, "" ); |
20 | static_assert( std::is_unsigned<const T>::value, "" ); |
21 | static_assert( std::is_unsigned<volatile T>::value, "" ); |
22 | static_assert( std::is_unsigned<const volatile T>::value, "" ); |
23 | #if TEST_STD_VER > 14 |
24 | static_assert( std::is_unsigned_v<T>, "" ); |
25 | static_assert( std::is_unsigned_v<const T>, "" ); |
26 | static_assert( std::is_unsigned_v<volatile T>, "" ); |
27 | static_assert( std::is_unsigned_v<const volatile T>, "" ); |
28 | #endif |
29 | } |
30 | |
31 | template <class T> |
32 | void test_is_not_unsigned() |
33 | { |
34 | static_assert(!std::is_unsigned<T>::value, "" ); |
35 | static_assert(!std::is_unsigned<const T>::value, "" ); |
36 | static_assert(!std::is_unsigned<volatile T>::value, "" ); |
37 | static_assert(!std::is_unsigned<const volatile T>::value, "" ); |
38 | #if TEST_STD_VER > 14 |
39 | static_assert(!std::is_unsigned_v<T>, "" ); |
40 | static_assert(!std::is_unsigned_v<const T>, "" ); |
41 | static_assert(!std::is_unsigned_v<volatile T>, "" ); |
42 | static_assert(!std::is_unsigned_v<const volatile T>, "" ); |
43 | #endif |
44 | } |
45 | |
46 | class Class |
47 | { |
48 | public: |
49 | ~Class(); |
50 | }; |
51 | |
52 | struct A; // incomplete |
53 | |
54 | class incomplete_type; |
55 | |
56 | class Empty {}; |
57 | |
58 | class NotEmpty { |
59 | virtual ~NotEmpty(); |
60 | }; |
61 | |
62 | union Union {}; |
63 | |
64 | struct bit_zero { |
65 | int : 0; |
66 | }; |
67 | |
68 | class Abstract { |
69 | virtual ~Abstract() = 0; |
70 | }; |
71 | |
72 | enum Enum { zero, one }; |
73 | |
74 | enum EnumSigned : int { two }; |
75 | |
76 | enum EnumUnsigned : unsigned { three }; |
77 | |
78 | enum class EnumClass { zero, one }; |
79 | |
80 | typedef void (*FunctionPtr)(); |
81 | |
82 | int main(int, char**) |
83 | { |
84 | // Cases where !is_arithmetic implies !is_unsigned |
85 | test_is_not_unsigned<std::nullptr_t>(); |
86 | test_is_not_unsigned<void>(); |
87 | test_is_not_unsigned<int&>(); |
88 | test_is_not_unsigned<int&&>(); |
89 | test_is_not_unsigned<Class>(); |
90 | test_is_not_unsigned<int*>(); |
91 | test_is_not_unsigned<const int*>(); |
92 | test_is_not_unsigned<char[3]>(); |
93 | test_is_not_unsigned<char[]>(); |
94 | test_is_not_unsigned<Union>(); |
95 | test_is_not_unsigned<Enum>(); |
96 | test_is_not_unsigned<EnumSigned>(); |
97 | test_is_not_unsigned<EnumUnsigned>(); |
98 | test_is_not_unsigned<EnumClass>(); |
99 | test_is_not_unsigned<FunctionPtr>(); |
100 | test_is_not_unsigned<Empty>(); |
101 | test_is_not_unsigned<incomplete_type>(); |
102 | test_is_not_unsigned<A>(); |
103 | test_is_not_unsigned<bit_zero>(); |
104 | test_is_not_unsigned<NotEmpty>(); |
105 | test_is_not_unsigned<Abstract>(); |
106 | |
107 | test_is_not_unsigned<signed char>(); |
108 | test_is_not_unsigned<short>(); |
109 | test_is_not_unsigned<int>(); |
110 | test_is_not_unsigned<long>(); |
111 | test_is_not_unsigned<float>(); |
112 | test_is_not_unsigned<double>(); |
113 | |
114 | test_is_unsigned<unsigned char>(); |
115 | test_is_unsigned<unsigned short>(); |
116 | test_is_unsigned<unsigned int>(); |
117 | test_is_unsigned<unsigned long>(); |
118 | |
119 | test_is_unsigned<bool>(); |
120 | test_is_unsigned<unsigned>(); |
121 | |
122 | #ifndef TEST_HAS_NO_INT128 |
123 | test_is_unsigned<__uint128_t>(); |
124 | test_is_not_unsigned<__int128_t>(); |
125 | #endif |
126 | |
127 | return 0; |
128 | } |
129 | |