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 // UNSUPPORTED: c++03, c++11, c++14, c++17 10 // UNSUPPORTED: libcpp-no-concepts 11 12 // template<class T> 13 // concept unsigned_integral = // see below 14 15 #include <concepts> 16 #include <type_traits> 17 18 #include "arithmetic.h" 19 20 template <typename T> 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); 26 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&>); 31 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&&>); 36 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*>); 41 42 static_assert(!std::unsigned_integral<T (*)()>); 43 static_assert(!std::unsigned_integral<T (&)()>); 44 static_assert(!std::unsigned_integral<T(&&)()>); 45 46 return result; 47 } 48 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>()); 55 56 // Whether bool and character types are signed or unsigned is impl-defined 57 static_assert(CheckUnsignedIntegralQualifiers<wchar_t>() == 58 !std::is_signed_v<wchar_t>); 59 static_assert(CheckUnsignedIntegralQualifiers<bool>() == 60 !std::is_signed_v<bool>); 61 static_assert(CheckUnsignedIntegralQualifiers<char>() == 62 !std::is_signed_v<char>); 63 static_assert(CheckUnsignedIntegralQualifiers<char8_t>() == 64 !std::is_signed_v<char8_t>); 65 static_assert(CheckUnsignedIntegralQualifiers<char16_t>() == 66 !std::is_signed_v<char16_t>); 67 static_assert(CheckUnsignedIntegralQualifiers<char32_t>() == 68 !std::is_signed_v<char32_t>); 69 70 // extended integers 71 #ifndef _LIBCPP_HAS_NO_INT128 72 static_assert(CheckUnsignedIntegralQualifiers<__uint128_t>()); 73 static_assert(!CheckUnsignedIntegralQualifiers<__int128_t>()); 74 #endif 75 76 // integer types that aren't unsigned integrals 77 static_assert(!CheckUnsignedIntegralQualifiers<signed char>()); 78 static_assert(!CheckUnsignedIntegralQualifiers<short>()); 79 static_assert(!CheckUnsignedIntegralQualifiers<int>()); 80 static_assert(!CheckUnsignedIntegralQualifiers<long>()); 81 static_assert(!CheckUnsignedIntegralQualifiers<long long>()); 82 83 static_assert(!std::unsigned_integral<void>); 84 static_assert(!CheckUnsignedIntegralQualifiers<float>()); 85 static_assert(!CheckUnsignedIntegralQualifiers<double>()); 86 static_assert(!CheckUnsignedIntegralQualifiers<long double>()); 87 88 static_assert(!CheckUnsignedIntegralQualifiers<ClassicEnum>()); 89 static_assert(!CheckUnsignedIntegralQualifiers<ScopedEnum>()); 90 static_assert(!CheckUnsignedIntegralQualifiers<EmptyStruct>()); 91 static_assert(!CheckUnsignedIntegralQualifiers<int EmptyStruct::*>()); 92 static_assert(!CheckUnsignedIntegralQualifiers<int (EmptyStruct::*)()>()); 93 94 static_assert(CheckSubsumption(0)); 95 static_assert(CheckSubsumption(0U)); 96 97 int main(int, char**) { return 0; } 98