| 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 | // function |
| 12 | |
| 13 | #include <type_traits> |
| 14 | #include "test_macros.h" |
| 15 | |
| 16 | class Class {}; |
| 17 | |
| 18 | enum Enum1 {}; |
| 19 | #if TEST_STD_VER >= 11 |
| 20 | enum class Enum2 : int {}; |
| 21 | #else |
| 22 | enum Enum2 {}; |
| 23 | #endif |
| 24 | |
| 25 | template <class T> |
| 26 | void test() |
| 27 | { |
| 28 | static_assert(!std::is_void<T>::value, "" ); |
| 29 | #if TEST_STD_VER > 11 |
| 30 | static_assert(!std::is_null_pointer<T>::value, "" ); |
| 31 | #endif |
| 32 | static_assert(!std::is_integral<T>::value, "" ); |
| 33 | static_assert(!std::is_floating_point<T>::value, "" ); |
| 34 | static_assert(!std::is_array<T>::value, "" ); |
| 35 | static_assert(!std::is_pointer<T>::value, "" ); |
| 36 | static_assert(!std::is_lvalue_reference<T>::value, "" ); |
| 37 | static_assert(!std::is_rvalue_reference<T>::value, "" ); |
| 38 | static_assert(!std::is_member_object_pointer<T>::value, "" ); |
| 39 | static_assert(!std::is_member_function_pointer<T>::value, "" ); |
| 40 | static_assert(!std::is_enum<T>::value, "" ); |
| 41 | static_assert(!std::is_union<T>::value, "" ); |
| 42 | static_assert(!std::is_class<T>::value, "" ); |
| 43 | static_assert( std::is_function<T>::value, "" ); |
| 44 | } |
| 45 | |
| 46 | // Since we can't actually add the const volatile and ref qualifiers once |
| 47 | // later let's use a macro to do it. |
| 48 | #define TEST_REGULAR(...) \ |
| 49 | test<__VA_ARGS__>(); \ |
| 50 | test<__VA_ARGS__ const>(); \ |
| 51 | test<__VA_ARGS__ volatile>(); \ |
| 52 | test<__VA_ARGS__ const volatile>() |
| 53 | |
| 54 | |
| 55 | #define TEST_REF_QUALIFIED(...) \ |
| 56 | test<__VA_ARGS__ &>(); \ |
| 57 | test<__VA_ARGS__ const &>(); \ |
| 58 | test<__VA_ARGS__ volatile &>(); \ |
| 59 | test<__VA_ARGS__ const volatile &>(); \ |
| 60 | test<__VA_ARGS__ &&>(); \ |
| 61 | test<__VA_ARGS__ const &&>(); \ |
| 62 | test<__VA_ARGS__ volatile &&>(); \ |
| 63 | test<__VA_ARGS__ const volatile &&>() |
| 64 | |
| 65 | struct incomplete_type; |
| 66 | |
| 67 | int main(int, char**) |
| 68 | { |
| 69 | TEST_REGULAR( void () ); |
| 70 | TEST_REGULAR( void (int) ); |
| 71 | TEST_REGULAR( int (double) ); |
| 72 | TEST_REGULAR( int (double, char) ); |
| 73 | TEST_REGULAR( void (...) ); |
| 74 | TEST_REGULAR( void (int, ...) ); |
| 75 | TEST_REGULAR( int (double, ...) ); |
| 76 | TEST_REGULAR( int (double, char, ...) ); |
| 77 | #if TEST_STD_VER >= 11 |
| 78 | TEST_REF_QUALIFIED( void () ); |
| 79 | TEST_REF_QUALIFIED( void (int) ); |
| 80 | TEST_REF_QUALIFIED( int (double) ); |
| 81 | TEST_REF_QUALIFIED( int (double, char) ); |
| 82 | TEST_REF_QUALIFIED( void (...) ); |
| 83 | TEST_REF_QUALIFIED( void (int, ...) ); |
| 84 | TEST_REF_QUALIFIED( int (double, ...) ); |
| 85 | TEST_REF_QUALIFIED( int (double, char, ...) ); |
| 86 | #endif |
| 87 | |
| 88 | // LWG#2582 |
| 89 | static_assert(!std::is_function<incomplete_type>::value, "" ); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |