1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // type_traits 11 12 // is_nothrow_destructible 13 14 #include <type_traits> 15 16 template <class T> test_is_nothrow_destructible()17void test_is_nothrow_destructible() 18 { 19 static_assert( std::is_nothrow_destructible<T>::value, ""); 20 static_assert( std::is_nothrow_destructible<const T>::value, ""); 21 static_assert( std::is_nothrow_destructible<volatile T>::value, ""); 22 static_assert( std::is_nothrow_destructible<const volatile T>::value, ""); 23 } 24 25 template <class T> test_has_not_nothrow_destructor()26void test_has_not_nothrow_destructor() 27 { 28 static_assert(!std::is_nothrow_destructible<T>::value, ""); 29 static_assert(!std::is_nothrow_destructible<const T>::value, ""); 30 static_assert(!std::is_nothrow_destructible<volatile T>::value, ""); 31 static_assert(!std::is_nothrow_destructible<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 void foo() = 0; 53 }; 54 55 class AbstractDestructor 56 { 57 virtual ~AbstractDestructor() = 0; 58 }; 59 60 struct A 61 { 62 ~A(); 63 }; 64 main()65int main() 66 { 67 test_has_not_nothrow_destructor<void>(); 68 test_has_not_nothrow_destructor<AbstractDestructor>(); 69 test_has_not_nothrow_destructor<NotEmpty>(); 70 71 #if __has_feature(cxx_noexcept) 72 test_is_nothrow_destructible<A>(); 73 #endif 74 test_is_nothrow_destructible<int&>(); 75 #if __has_feature(cxx_unrestricted_unions) 76 test_is_nothrow_destructible<Union>(); 77 #endif 78 #if __has_feature(cxx_access_control_sfinae) 79 test_is_nothrow_destructible<Empty>(); 80 #endif 81 test_is_nothrow_destructible<int>(); 82 test_is_nothrow_destructible<double>(); 83 test_is_nothrow_destructible<int*>(); 84 test_is_nothrow_destructible<const int*>(); 85 test_is_nothrow_destructible<char[3]>(); 86 test_is_nothrow_destructible<char[3]>(); 87 test_is_nothrow_destructible<Abstract>(); 88 #if __has_feature(cxx_noexcept) 89 test_is_nothrow_destructible<bit_zero>(); 90 #endif 91 } 92