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 | |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 12 | // is_nothrow_copy_assignable |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 13 | |
| 14 | #include <type_traits> |
| 15 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 16 | template <class T> |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 17 | void test_has_nothrow_assign() |
| 18 | { |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 19 | static_assert( std::is_nothrow_copy_assignable<T>::value, ""); |
| 20 | } |
| 21 | |
| 22 | template <class T> |
| 23 | void test_has_not_nothrow_assign() |
| 24 | { |
| 25 | static_assert(!std::is_nothrow_copy_assignable<T>::value, ""); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | class Empty |
| 29 | { |
| 30 | }; |
| 31 | |
Howard Hinnant | 2703111 | 2010-09-08 16:39:18 +0000 | [diff] [blame] | 32 | struct NotEmpty |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 33 | { |
| 34 | virtual ~NotEmpty(); |
| 35 | }; |
| 36 | |
| 37 | union Union {}; |
| 38 | |
| 39 | struct bit_zero |
| 40 | { |
| 41 | int : 0; |
| 42 | }; |
| 43 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 44 | struct A |
| 45 | { |
| 46 | A& operator=(const A&); |
| 47 | }; |
| 48 | |
| 49 | int main() |
| 50 | { |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 51 | test_has_nothrow_assign<int&>(); |
| 52 | test_has_nothrow_assign<Union>(); |
| 53 | test_has_nothrow_assign<Empty>(); |
| 54 | test_has_nothrow_assign<int>(); |
| 55 | test_has_nothrow_assign<double>(); |
| 56 | test_has_nothrow_assign<int*>(); |
| 57 | test_has_nothrow_assign<const int*>(); |
| 58 | test_has_nothrow_assign<NotEmpty>(); |
| 59 | test_has_nothrow_assign<bit_zero>(); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 60 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 61 | test_has_not_nothrow_assign<const int>(); |
| 62 | test_has_not_nothrow_assign<void>(); |
| 63 | test_has_not_nothrow_assign<A>(); |
| 64 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 65 | } |