Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // type_traits |
| 11 | |
| 12 | // member_function_pointer |
| 13 | |
| 14 | #include <type_traits> |
Eric Fiselier | 724b5ab | 2015-06-13 00:33:13 +0000 | [diff] [blame] | 15 | #include "test_macros.h" |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 16 | |
| 17 | template <class T> |
| 18 | void test_member_function_pointer_imp() |
| 19 | { |
| 20 | static_assert(!std::is_void<T>::value, ""); |
Eric Fiselier | 724b5ab | 2015-06-13 00:33:13 +0000 | [diff] [blame] | 21 | #if TEST_STD_VER > 11 |
Marshall Clow | 79d8c99 | 2013-10-05 21:21:17 +0000 | [diff] [blame] | 22 | static_assert(!std::is_null_pointer<T>::value, ""); |
| 23 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 24 | static_assert(!std::is_integral<T>::value, ""); |
| 25 | static_assert(!std::is_floating_point<T>::value, ""); |
| 26 | static_assert(!std::is_array<T>::value, ""); |
| 27 | static_assert(!std::is_pointer<T>::value, ""); |
| 28 | static_assert(!std::is_lvalue_reference<T>::value, ""); |
| 29 | static_assert(!std::is_rvalue_reference<T>::value, ""); |
| 30 | static_assert(!std::is_member_object_pointer<T>::value, ""); |
| 31 | static_assert( std::is_member_function_pointer<T>::value, ""); |
| 32 | static_assert(!std::is_enum<T>::value, ""); |
| 33 | static_assert(!std::is_union<T>::value, ""); |
| 34 | static_assert(!std::is_class<T>::value, ""); |
| 35 | static_assert(!std::is_function<T>::value, ""); |
| 36 | } |
| 37 | |
| 38 | template <class T> |
| 39 | void test_member_function_pointer() |
| 40 | { |
| 41 | test_member_function_pointer_imp<T>(); |
| 42 | test_member_function_pointer_imp<const T>(); |
| 43 | test_member_function_pointer_imp<volatile T>(); |
| 44 | test_member_function_pointer_imp<const volatile T>(); |
| 45 | } |
| 46 | |
| 47 | class Class |
| 48 | { |
| 49 | }; |
| 50 | |
| 51 | int main() |
| 52 | { |
| 53 | test_member_function_pointer<void (Class::*)()>(); |
| 54 | test_member_function_pointer<void (Class::*)(int)>(); |
| 55 | test_member_function_pointer<void (Class::*)(int, char)>(); |
Marshall Clow | 4f3368e | 2014-05-29 01:10:28 +0000 | [diff] [blame] | 56 | |
| 57 | test_member_function_pointer<void (Class::*)() const>(); |
| 58 | test_member_function_pointer<void (Class::*)(int) const>(); |
| 59 | test_member_function_pointer<void (Class::*)(int, char) const>(); |
| 60 | |
| 61 | test_member_function_pointer<void (Class::*)() volatile>(); |
| 62 | test_member_function_pointer<void (Class::*)(int) volatile>(); |
| 63 | test_member_function_pointer<void (Class::*)(int, char) volatile>(); |
| 64 | |
Eric Fiselier | 63648cf | 2014-08-19 16:31:47 +0000 | [diff] [blame] | 65 | test_member_function_pointer<void (Class::*)(...)>(); |
| 66 | test_member_function_pointer<void (Class::*)(int, ...)>(); |
| 67 | test_member_function_pointer<void (Class::*)(int, char, ...)>(); |
| 68 | |
| 69 | test_member_function_pointer<void (Class::*)(...) const>(); |
| 70 | test_member_function_pointer<void (Class::*)(int, ...) const>(); |
| 71 | test_member_function_pointer<void (Class::*)(int, char, ...) const>(); |
| 72 | |
| 73 | test_member_function_pointer<void (Class::*)(...) volatile>(); |
| 74 | test_member_function_pointer<void (Class::*)(int, ...) volatile>(); |
| 75 | test_member_function_pointer<void (Class::*)(int, char, ...) volatile>(); |
| 76 | |
Marshall Clow | 4f3368e | 2014-05-29 01:10:28 +0000 | [diff] [blame] | 77 | // reference qualifiers on functions are a C++11 extension |
Eric Fiselier | 724b5ab | 2015-06-13 00:33:13 +0000 | [diff] [blame] | 78 | #if TEST_STD_VER >= 11 |
Marshall Clow | 4f3368e | 2014-05-29 01:10:28 +0000 | [diff] [blame] | 79 | test_member_function_pointer<void (Class::*)() &>(); |
| 80 | test_member_function_pointer<void (Class::*)(int) &>(); |
| 81 | test_member_function_pointer<void (Class::*)(int, char) &>(); |
Eric Fiselier | 63648cf | 2014-08-19 16:31:47 +0000 | [diff] [blame] | 82 | test_member_function_pointer<void (Class::*)(...) &>(); |
| 83 | test_member_function_pointer<void (Class::*)(int,...) &>(); |
| 84 | test_member_function_pointer<void (Class::*)(int, char,...) &>(); |
| 85 | |
Eric Fiselier | 724b5ab | 2015-06-13 00:33:13 +0000 | [diff] [blame] | 86 | test_member_function_pointer<void (Class::*)() const &>(); |
| 87 | test_member_function_pointer<void (Class::*)(int) const &>(); |
| 88 | test_member_function_pointer<void (Class::*)(int, char) const &>(); |
| 89 | test_member_function_pointer<void (Class::*)(...) const &>(); |
| 90 | test_member_function_pointer<void (Class::*)(int,...) const &>(); |
| 91 | test_member_function_pointer<void (Class::*)(int, char,...) const &>(); |
| 92 | |
| 93 | test_member_function_pointer<void (Class::*)() volatile &>(); |
| 94 | test_member_function_pointer<void (Class::*)(int) volatile &>(); |
| 95 | test_member_function_pointer<void (Class::*)(int, char) volatile &>(); |
| 96 | test_member_function_pointer<void (Class::*)(...) volatile &>(); |
| 97 | test_member_function_pointer<void (Class::*)(int,...) volatile &>(); |
| 98 | test_member_function_pointer<void (Class::*)(int, char,...) volatile &>(); |
| 99 | |
| 100 | test_member_function_pointer<void (Class::*)() const volatile &>(); |
| 101 | test_member_function_pointer<void (Class::*)(int) const volatile &>(); |
| 102 | test_member_function_pointer<void (Class::*)(int, char) const volatile &>(); |
| 103 | test_member_function_pointer<void (Class::*)(...) const volatile &>(); |
| 104 | test_member_function_pointer<void (Class::*)(int,...) const volatile &>(); |
| 105 | test_member_function_pointer<void (Class::*)(int, char,...) const volatile &>(); |
| 106 | |
| 107 | // RValue qualifiers |
| 108 | test_member_function_pointer<void (Class::*)() &&>(); |
| 109 | test_member_function_pointer<void (Class::*)(int) &&>(); |
| 110 | test_member_function_pointer<void (Class::*)(int, char) &&>(); |
| 111 | test_member_function_pointer<void (Class::*)(...) &&>(); |
| 112 | test_member_function_pointer<void (Class::*)(int,...) &&>(); |
| 113 | test_member_function_pointer<void (Class::*)(int, char,...) &&>(); |
| 114 | |
| 115 | test_member_function_pointer<void (Class::*)() const &&>(); |
| 116 | test_member_function_pointer<void (Class::*)(int) const &&>(); |
| 117 | test_member_function_pointer<void (Class::*)(int, char) const &&>(); |
| 118 | test_member_function_pointer<void (Class::*)(...) const &&>(); |
| 119 | test_member_function_pointer<void (Class::*)(int,...) const &&>(); |
| 120 | test_member_function_pointer<void (Class::*)(int, char,...) const &&>(); |
| 121 | |
| 122 | test_member_function_pointer<void (Class::*)() volatile &&>(); |
| 123 | test_member_function_pointer<void (Class::*)(int) volatile &&>(); |
| 124 | test_member_function_pointer<void (Class::*)(int, char) volatile &&>(); |
Eric Fiselier | 63648cf | 2014-08-19 16:31:47 +0000 | [diff] [blame] | 125 | test_member_function_pointer<void (Class::*)(...) volatile &&>(); |
| 126 | test_member_function_pointer<void (Class::*)(int,...) volatile &&>(); |
| 127 | test_member_function_pointer<void (Class::*)(int, char,...) volatile &&>(); |
Eric Fiselier | 724b5ab | 2015-06-13 00:33:13 +0000 | [diff] [blame] | 128 | |
| 129 | test_member_function_pointer<void (Class::*)() const volatile &&>(); |
| 130 | test_member_function_pointer<void (Class::*)(int) const volatile &&>(); |
| 131 | test_member_function_pointer<void (Class::*)(int, char) const volatile &&>(); |
| 132 | test_member_function_pointer<void (Class::*)(...) const volatile &&>(); |
| 133 | test_member_function_pointer<void (Class::*)(int,...) const volatile &&>(); |
| 134 | test_member_function_pointer<void (Class::*)(int, char,...) const volatile &&>(); |
Marshall Clow | 4f3368e | 2014-05-29 01:10:28 +0000 | [diff] [blame] | 135 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 136 | } |