blob: b1df4f2d3f4cc8ab460eb88088a2d36c74d61db3 [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// type_traits
11
12// function
13
14#include <type_traits>
15
Eric Fiselier89465dc2015-02-18 16:31:46 +000016using namespace std;
17
18class Class {};
19
20enum Enum1 {};
Dan Albert1d4a1ed2016-05-25 22:36:09 -070021#if __cplusplus >= 201103L
Eric Fiselier89465dc2015-02-18 16:31:46 +000022enum class Enum2 : int {};
23#else
24enum Enum2 {};
25#endif
26
Howard Hinnantc52f43e2010-08-22 00:59:46 +000027template <class T>
Eric Fiselier89465dc2015-02-18 16:31:46 +000028void test()
Howard Hinnantc52f43e2010-08-22 00:59:46 +000029{
30 static_assert(!std::is_void<T>::value, "");
Dan Albert1d4a1ed2016-05-25 22:36:09 -070031#if _LIBCPP_STD_VER > 11
Marshall Clow79d8c992013-10-05 21:21:17 +000032 static_assert(!std::is_null_pointer<T>::value, "");
33#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000034 static_assert(!std::is_integral<T>::value, "");
35 static_assert(!std::is_floating_point<T>::value, "");
36 static_assert(!std::is_array<T>::value, "");
37 static_assert(!std::is_pointer<T>::value, "");
38 static_assert(!std::is_lvalue_reference<T>::value, "");
39 static_assert(!std::is_rvalue_reference<T>::value, "");
40 static_assert(!std::is_member_object_pointer<T>::value, "");
41 static_assert(!std::is_member_function_pointer<T>::value, "");
42 static_assert(!std::is_enum<T>::value, "");
43 static_assert(!std::is_union<T>::value, "");
44 static_assert(!std::is_class<T>::value, "");
45 static_assert( std::is_function<T>::value, "");
46}
47
Eric Fiselier89465dc2015-02-18 16:31:46 +000048// Since we can't actually add the const volatile and ref qualifiers once
49// later let's use a macro to do it.
50#define TEST_REGULAR(...) \
51 test<__VA_ARGS__>(); \
52 test<__VA_ARGS__ const>(); \
53 test<__VA_ARGS__ volatile>(); \
54 test<__VA_ARGS__ const volatile>()
55
56
57#define TEST_REF_QUALIFIED(...) \
58 test<__VA_ARGS__ &>(); \
59 test<__VA_ARGS__ const &>(); \
60 test<__VA_ARGS__ volatile &>(); \
61 test<__VA_ARGS__ const volatile &>(); \
62 test<__VA_ARGS__ &&>(); \
63 test<__VA_ARGS__ const &&>(); \
64 test<__VA_ARGS__ volatile &&>(); \
65 test<__VA_ARGS__ const volatile &&>()
66
Howard Hinnantc52f43e2010-08-22 00:59:46 +000067
68int main()
69{
Eric Fiselier89465dc2015-02-18 16:31:46 +000070 TEST_REGULAR( void () );
71 TEST_REGULAR( void (int) );
72 TEST_REGULAR( int (double) );
73 TEST_REGULAR( int (double, char) );
74 TEST_REGULAR( void (...) );
75 TEST_REGULAR( void (int, ...) );
76 TEST_REGULAR( int (double, ...) );
77 TEST_REGULAR( int (double, char, ...) );
Dan Albert1d4a1ed2016-05-25 22:36:09 -070078#if __cplusplus >= 201103L
Eric Fiselier89465dc2015-02-18 16:31:46 +000079 TEST_REF_QUALIFIED( void () );
80 TEST_REF_QUALIFIED( void (int) );
81 TEST_REF_QUALIFIED( int (double) );
82 TEST_REF_QUALIFIED( int (double, char) );
83 TEST_REF_QUALIFIED( void (...) );
84 TEST_REF_QUALIFIED( void (int, ...) );
85 TEST_REF_QUALIFIED( int (double, ...) );
86 TEST_REF_QUALIFIED( int (double, char, ...) );
87#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000088}