1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // concept unsigned_integral = // see below
15 #include <type_traits>
17 #include "arithmetic.h"
18 #include "test_macros.h"
21 constexpr bool CheckUnsignedIntegralQualifiers() {
22 constexpr bool result
= std::unsigned_integral
<T
>;
23 static_assert(std::unsigned_integral
<const T
> == result
);
24 static_assert(std::unsigned_integral
<volatile T
> == result
);
25 static_assert(std::unsigned_integral
<const volatile T
> == result
);
27 static_assert(!std::unsigned_integral
<T
&>);
28 static_assert(!std::unsigned_integral
<const T
&>);
29 static_assert(!std::unsigned_integral
<volatile T
&>);
30 static_assert(!std::unsigned_integral
<const volatile T
&>);
32 static_assert(!std::unsigned_integral
<T
&&>);
33 static_assert(!std::unsigned_integral
<const T
&&>);
34 static_assert(!std::unsigned_integral
<volatile T
&&>);
35 static_assert(!std::unsigned_integral
<const volatile T
&&>);
37 static_assert(!std::unsigned_integral
<T
*>);
38 static_assert(!std::unsigned_integral
<const T
*>);
39 static_assert(!std::unsigned_integral
<volatile T
*>);
40 static_assert(!std::unsigned_integral
<const volatile T
*>);
42 static_assert(!std::unsigned_integral
<T (*)()>);
43 static_assert(!std::unsigned_integral
<T (&)()>);
44 static_assert(!std::unsigned_integral
<T (&&)()>);
49 // standard unsigned types
50 static_assert(CheckUnsignedIntegralQualifiers
<unsigned char>());
51 static_assert(CheckUnsignedIntegralQualifiers
<unsigned short>());
52 static_assert(CheckUnsignedIntegralQualifiers
<unsigned int>());
53 static_assert(CheckUnsignedIntegralQualifiers
<unsigned long>());
54 static_assert(CheckUnsignedIntegralQualifiers
<unsigned long long>());
56 // Whether bool and character types are signed or unsigned is impl-defined
57 static_assert(CheckUnsignedIntegralQualifiers
<wchar_t>() == !std::is_signed_v
<wchar_t>);
58 static_assert(CheckUnsignedIntegralQualifiers
<bool>() == !std::is_signed_v
<bool>);
59 static_assert(CheckUnsignedIntegralQualifiers
<char>() == !std::is_signed_v
<char>);
60 static_assert(CheckUnsignedIntegralQualifiers
<char8_t
>() == !std::is_signed_v
<char8_t
>);
61 static_assert(CheckUnsignedIntegralQualifiers
<char16_t
>() == !std::is_signed_v
<char16_t
>);
62 static_assert(CheckUnsignedIntegralQualifiers
<char32_t
>() == !std::is_signed_v
<char32_t
>);
65 #ifndef TEST_HAS_NO_INT128
66 static_assert(CheckUnsignedIntegralQualifiers
<__uint128_t
>());
67 static_assert(!CheckUnsignedIntegralQualifiers
<__int128_t
>());
70 // integer types that aren't unsigned integrals
71 static_assert(!CheckUnsignedIntegralQualifiers
<signed char>());
72 static_assert(!CheckUnsignedIntegralQualifiers
<short>());
73 static_assert(!CheckUnsignedIntegralQualifiers
<int>());
74 static_assert(!CheckUnsignedIntegralQualifiers
<long>());
75 static_assert(!CheckUnsignedIntegralQualifiers
<long long>());
77 static_assert(!std::unsigned_integral
<void>);
78 static_assert(!CheckUnsignedIntegralQualifiers
<float>());
79 static_assert(!CheckUnsignedIntegralQualifiers
<double>());
80 static_assert(!CheckUnsignedIntegralQualifiers
<long double>());
82 static_assert(!CheckUnsignedIntegralQualifiers
<ClassicEnum
>());
83 static_assert(!CheckUnsignedIntegralQualifiers
<ScopedEnum
>());
84 static_assert(!CheckUnsignedIntegralQualifiers
<EmptyStruct
>());
85 static_assert(!CheckUnsignedIntegralQualifiers
<int EmptyStruct::*>());
86 static_assert(!CheckUnsignedIntegralQualifiers
<int (EmptyStruct::*)()>());
88 static_assert(CheckSubsumption(0));
89 static_assert(CheckSubsumption(0U));