1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// type_traits
// is_scoped_enum // C++2b
#include <type_traits>
#include <cstddef> // for std::nullptr_t
#include "test_macros.h"
template <class T>
void test_positive() {
static_assert(std::is_scoped_enum<T>::value);
static_assert(std::is_scoped_enum<const T>::value);
static_assert(std::is_scoped_enum<volatile T>::value);
static_assert(std::is_scoped_enum<const volatile T>::value);
static_assert(std::is_scoped_enum_v<T>);
static_assert(std::is_scoped_enum_v<const T>);
static_assert(std::is_scoped_enum_v<volatile T>);
static_assert(std::is_scoped_enum_v<const volatile T>);
}
template <class T>
void test_negative() {
static_assert(!std::is_scoped_enum<T>::value);
static_assert(!std::is_scoped_enum<const T>::value);
static_assert(!std::is_scoped_enum<volatile T>::value);
static_assert(!std::is_scoped_enum<const volatile T>::value);
static_assert(!std::is_scoped_enum_v<T>);
static_assert(!std::is_scoped_enum_v<const T>);
static_assert(!std::is_scoped_enum_v<volatile T>);
static_assert(!std::is_scoped_enum_v<const volatile T>);
}
class Empty {};
class NotEmpty {
virtual ~NotEmpty();
};
union Union {};
struct bit_zero {
int : 0;
};
class Abstract {
virtual ~Abstract() = 0;
};
enum Enum { zero, one };
enum class CEnum1 { zero, one };
enum class CEnum2;
enum class CEnum3 : short;
struct incomplete_type;
using FunctionPtr = void (*)();
using FunctionType = void();
struct TestMembers {
static int static_method(int) { return 0; }
int method() { return 0; }
enum E1 { m_zero, m_one };
enum class CE1;
};
void func1();
int func2(int);
int main(int, char**) {
test_positive<CEnum1>();
test_positive<CEnum2>();
test_positive<CEnum3>();
test_positive<TestMembers::CE1>();
test_negative<Enum>();
test_negative<TestMembers::E1>();
test_negative<std::nullptr_t>();
test_negative<void>();
test_negative<int>();
test_negative<int&>();
test_negative<int&&>();
test_negative<int*>();
test_negative<double>();
test_negative<const int*>();
test_negative<char[3]>();
test_negative<char[]>();
test_negative<Union>();
test_negative<Empty>();
test_negative<bit_zero>();
test_negative<NotEmpty>();
test_negative<Abstract>();
test_negative<FunctionPtr>();
test_negative<FunctionType>();
test_negative<incomplete_type>();
test_negative<int TestMembers::*>();
test_negative<void (TestMembers::*)()>();
test_negative<decltype(func1)>();
test_negative<decltype(&func1)>();
test_negative<decltype(func2)>();
test_negative<decltype(&func2)>();
test_negative<decltype(TestMembers::static_method)>();
test_negative<decltype(&TestMembers::static_method)>();
test_negative<decltype(&TestMembers::method)>();
return 0;
}
|