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 | // is_polymorphic |
| 13 | |
| 14 | #include <type_traits> |
| 15 | |
| 16 | template <class T> |
| 17 | void test_is_polymorphic() |
| 18 | { |
| 19 | static_assert( std::is_polymorphic<T>::value, ""); |
| 20 | static_assert( std::is_polymorphic<const T>::value, ""); |
| 21 | static_assert( std::is_polymorphic<volatile T>::value, ""); |
| 22 | static_assert( std::is_polymorphic<const volatile T>::value, ""); |
| 23 | } |
| 24 | |
| 25 | template <class T> |
| 26 | void test_is_not_polymorphic() |
| 27 | { |
| 28 | static_assert(!std::is_polymorphic<T>::value, ""); |
| 29 | static_assert(!std::is_polymorphic<const T>::value, ""); |
| 30 | static_assert(!std::is_polymorphic<volatile T>::value, ""); |
| 31 | static_assert(!std::is_polymorphic<const volatile T>::value, ""); |
| 32 | } |
| 33 | |
| 34 | class Empty |
| 35 | { |
| 36 | }; |
| 37 | |
| 38 | class NotEmpty |
| 39 | { |
| 40 | virtual ~NotEmpty(); |
| 41 | }; |
| 42 | |
| 43 | union Union {}; |
| 44 | |
| 45 | struct bit_zero |
| 46 | { |
| 47 | int : 0; |
| 48 | }; |
| 49 | |
| 50 | class Abstract |
| 51 | { |
| 52 | virtual ~Abstract() = 0; |
| 53 | }; |
| 54 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 55 | #if __has_feature(cxx_attributes) |
Howard Hinnant | 11a50ac | 2013-04-02 21:25:06 +0000 | [diff] [blame] | 56 | class Final final { |
| 57 | }; |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 58 | #else |
| 59 | class Final { |
| 60 | }; |
| 61 | #endif |
Howard Hinnant | 11a50ac | 2013-04-02 21:25:06 +0000 | [diff] [blame] | 62 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 63 | int main() |
| 64 | { |
| 65 | test_is_not_polymorphic<void>(); |
| 66 | test_is_not_polymorphic<int&>(); |
| 67 | test_is_not_polymorphic<int>(); |
| 68 | test_is_not_polymorphic<double>(); |
| 69 | test_is_not_polymorphic<int*>(); |
| 70 | test_is_not_polymorphic<const int*>(); |
| 71 | test_is_not_polymorphic<char[3]>(); |
Marshall Clow | e33e03e | 2014-09-02 16:19:38 +0000 | [diff] [blame] | 72 | test_is_not_polymorphic<char[]>(); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 73 | test_is_not_polymorphic<Union>(); |
| 74 | test_is_not_polymorphic<Empty>(); |
| 75 | test_is_not_polymorphic<bit_zero>(); |
Howard Hinnant | 11a50ac | 2013-04-02 21:25:06 +0000 | [diff] [blame] | 76 | test_is_not_polymorphic<Final>(); |
| 77 | test_is_not_polymorphic<NotEmpty&>(); |
| 78 | test_is_not_polymorphic<Abstract&>(); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 79 | |
| 80 | test_is_polymorphic<NotEmpty>(); |
| 81 | test_is_polymorphic<Abstract>(); |
| 82 | } |