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

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