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_copy_constructible 13 14 #include <type_traits> 15 #include "test_macros.h" 16 17 template <class T> 18 void test_is_nothrow_copy_constructible() 19 { 20 static_assert( std::is_nothrow_copy_constructible<T>::value, ""); 21 static_assert( std::is_nothrow_copy_constructible<const T>::value, ""); 22 #if TEST_STD_VER > 14 23 static_assert( std::is_nothrow_copy_constructible_v<T>, ""); 24 static_assert( std::is_nothrow_copy_constructible_v<const T>, ""); 25 #endif 26 } 27 28 template <class T> 29 void test_has_not_nothrow_copy_constructor() 30 { 31 static_assert(!std::is_nothrow_copy_constructible<T>::value, ""); 32 static_assert(!std::is_nothrow_copy_constructible<const T>::value, ""); 33 static_assert(!std::is_nothrow_copy_constructible<volatile T>::value, ""); 34 static_assert(!std::is_nothrow_copy_constructible<const volatile T>::value, ""); 35 #if TEST_STD_VER > 14 36 static_assert(!std::is_nothrow_copy_constructible_v<T>, ""); 37 static_assert(!std::is_nothrow_copy_constructible_v<const T>, ""); 38 static_assert(!std::is_nothrow_copy_constructible_v<volatile T>, ""); 39 static_assert(!std::is_nothrow_copy_constructible_v<const volatile T>, ""); 40 #endif 41 } 42 43 class Empty 44 { 45 }; 46 47 union Union {}; 48 49 struct bit_zero 50 { 51 int : 0; 52 }; 53 54 struct A 55 { 56 A(const A&); 57 }; 58 59 int main() 60 { 61 test_has_not_nothrow_copy_constructor<void>(); 62 test_has_not_nothrow_copy_constructor<A>(); 63 64 test_is_nothrow_copy_constructible<int&>(); 65 test_is_nothrow_copy_constructible<Union>(); 66 test_is_nothrow_copy_constructible<Empty>(); 67 test_is_nothrow_copy_constructible<int>(); 68 test_is_nothrow_copy_constructible<double>(); 69 test_is_nothrow_copy_constructible<int*>(); 70 test_is_nothrow_copy_constructible<const int*>(); 71 test_is_nothrow_copy_constructible<bit_zero>(); 72 } 73