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 | // template <class T, class... Args> |
| 13 | // struct is_nothrow_constructible; |
| 14 | |
| 15 | #include <type_traits> |
| 16 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 17 | template <class T> |
| 18 | void test_is_nothrow_constructible() |
| 19 | { |
| 20 | static_assert(( std::is_nothrow_constructible<T>::value), ""); |
| 21 | } |
| 22 | |
| 23 | template <class T, class A0> |
| 24 | void test_is_nothrow_constructible() |
| 25 | { |
| 26 | static_assert(( std::is_nothrow_constructible<T, A0>::value), ""); |
| 27 | } |
| 28 | |
| 29 | template <class T> |
| 30 | void test_is_not_nothrow_constructible() |
| 31 | { |
| 32 | static_assert((!std::is_nothrow_constructible<T>::value), ""); |
| 33 | } |
| 34 | |
| 35 | template <class T, class A0> |
| 36 | void test_is_not_nothrow_constructible() |
| 37 | { |
| 38 | static_assert((!std::is_nothrow_constructible<T, A0>::value), ""); |
| 39 | } |
| 40 | |
| 41 | template <class T, class A0, class A1> |
| 42 | void test_is_not_nothrow_constructible() |
| 43 | { |
| 44 | static_assert((!std::is_nothrow_constructible<T, A0, A1>::value), ""); |
| 45 | } |
| 46 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 47 | class Empty |
| 48 | { |
| 49 | }; |
| 50 | |
| 51 | class NotEmpty |
| 52 | { |
| 53 | virtual ~NotEmpty(); |
| 54 | }; |
| 55 | |
| 56 | union Union {}; |
| 57 | |
| 58 | struct bit_zero |
| 59 | { |
| 60 | int : 0; |
| 61 | }; |
| 62 | |
| 63 | class Abstract |
| 64 | { |
| 65 | virtual ~Abstract() = 0; |
| 66 | }; |
| 67 | |
| 68 | struct A |
| 69 | { |
| 70 | A(const A&); |
| 71 | }; |
| 72 | |
Marshall Clow | d132bf4 | 2014-09-22 23:58:00 +0000 | [diff] [blame] | 73 | struct C |
| 74 | { |
| 75 | C(C&); // not const |
| 76 | void operator=(C&); // not const |
| 77 | }; |
| 78 | |
Marshall Clow | df9722e | 2014-10-07 21:42:12 +0000 | [diff] [blame] | 79 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 80 | struct Tuple { |
| 81 | Tuple(Empty&&) noexcept {} |
| 82 | }; |
| 83 | #endif |
| 84 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 85 | int main() |
| 86 | { |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 87 | test_is_nothrow_constructible<int> (); |
| 88 | test_is_nothrow_constructible<int, const int&> (); |
| 89 | test_is_nothrow_constructible<Empty> (); |
| 90 | test_is_nothrow_constructible<Empty, const Empty&> (); |
Marshall Clow | df9722e | 2014-10-07 21:42:12 +0000 | [diff] [blame] | 91 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 92 | test_is_nothrow_constructible<Tuple &&, Empty> (); // See bug #19616. |
| 93 | #endif |
| 94 | |
Marshall Clow | 933afa9 | 2013-07-04 00:10:01 +0000 | [diff] [blame] | 95 | test_is_not_nothrow_constructible<A, int> (); |
| 96 | test_is_not_nothrow_constructible<A, int, double> (); |
| 97 | test_is_not_nothrow_constructible<A> (); |
Marshall Clow | d132bf4 | 2014-09-22 23:58:00 +0000 | [diff] [blame] | 98 | test_is_not_nothrow_constructible<C> (); |
Marshall Clow | df9722e | 2014-10-07 21:42:12 +0000 | [diff] [blame] | 99 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 100 | static_assert(!std::is_constructible<Tuple&, Empty>::value, ""); |
| 101 | test_is_not_nothrow_constructible<Tuple &, Empty> (); // See bug #19616. |
| 102 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 103 | } |