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_literal_type
12
13 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
14 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
15
16 #include <type_traits>
17 #include <cstddef> // for std::nullptr_t
18 #include "test_macros.h"
19
20 template <class T>
test_is_literal_type()21 void test_is_literal_type()
22 {
23 static_assert( std::is_literal_type<T>::value, "");
24 static_assert( std::is_literal_type<const T>::value, "");
25 static_assert( std::is_literal_type<volatile T>::value, "");
26 static_assert( std::is_literal_type<const volatile T>::value, "");
27 #if TEST_STD_VER > 14
28 static_assert( std::is_literal_type_v<T>, "");
29 static_assert( std::is_literal_type_v<const T>, "");
30 static_assert( std::is_literal_type_v<volatile T>, "");
31 static_assert( std::is_literal_type_v<const volatile T>, "");
32 #endif
33 }
34
35 template <class T>
test_is_not_literal_type()36 void test_is_not_literal_type()
37 {
38 static_assert(!std::is_literal_type<T>::value, "");
39 static_assert(!std::is_literal_type<const T>::value, "");
40 static_assert(!std::is_literal_type<volatile T>::value, "");
41 static_assert(!std::is_literal_type<const volatile T>::value, "");
42 #if TEST_STD_VER > 14
43 static_assert(!std::is_literal_type_v<T>, "");
44 static_assert(!std::is_literal_type_v<const T>, "");
45 static_assert(!std::is_literal_type_v<volatile T>, "");
46 static_assert(!std::is_literal_type_v<const volatile T>, "");
47 #endif
48 }
49
50 class Empty
51 {
52 };
53
54 class NotEmpty
55 {
56 virtual ~NotEmpty();
57 };
58
59 union Union {};
60
61 struct bit_zero
62 {
63 int : 0;
64 };
65
66 class Abstract
67 {
68 virtual ~Abstract() = 0;
69 };
70
71 enum Enum {zero, one};
72
73 typedef void (*FunctionPtr)();
74
main(int,char **)75 int main(int, char**)
76 {
77 #if TEST_STD_VER >= 11
78 test_is_literal_type<std::nullptr_t>();
79 #endif
80
81 // Before C++14, void was not a literal type
82 // In C++14, cv-void is a literal type
83 #if TEST_STD_VER < 14
84 test_is_not_literal_type<void>();
85 #else
86 test_is_literal_type<void>();
87 #endif
88
89 test_is_literal_type<int>();
90 test_is_literal_type<int*>();
91 test_is_literal_type<const int*>();
92 test_is_literal_type<int&>();
93 #if TEST_STD_VER >= 11
94 test_is_literal_type<int&&>();
95 #endif
96 test_is_literal_type<double>();
97 test_is_literal_type<char[3]>();
98 test_is_literal_type<char[]>();
99 test_is_literal_type<Empty>();
100 test_is_literal_type<bit_zero>();
101 test_is_literal_type<Union>();
102 test_is_literal_type<Enum>();
103 test_is_literal_type<FunctionPtr>();
104
105 test_is_not_literal_type<NotEmpty>();
106 test_is_not_literal_type<Abstract>();
107
108 return 0;
109 }
110