Debian Codegraph @

libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp

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