| 1 |
// { dg-do compile { target c++14 } } |
| 2 |
// PR c++/96090 |
| 3 |
|
| 4 |
template <typename T> |
| 5 |
constexpr bool is_nothrow_default_constructible_v |
| 6 |
= __is_nothrow_constructible(T); |
| 7 |
template <typename T> |
| 8 |
constexpr bool is_nothrow_copy_constructible_v |
| 9 |
= __is_nothrow_constructible(T, const T&); |
| 10 |
template <typename T> |
| 11 |
constexpr bool is_nothrow_move_constructible_v |
| 12 |
= __is_nothrow_constructible(T, T&&); |
| 13 |
template <typename T> |
| 14 |
constexpr bool is_nothrow_copy_assignable_v |
| 15 |
= __is_nothrow_assignable(T, const T&); |
| 16 |
template <typename T> |
| 17 |
constexpr bool is_nothrow_move_assignable_v |
| 18 |
= __is_nothrow_assignable(T, T&&); |
| 19 |
|
| 20 |
struct yesthrow_t { |
| 21 |
yesthrow_t() noexcept(false) = default; |
| 22 |
yesthrow_t(const yesthrow_t&) noexcept(false) = default; |
| 23 |
yesthrow_t(yesthrow_t&&) noexcept(false) = default; |
| 24 |
yesthrow_t& operator=(const yesthrow_t&) noexcept(false) = default; |
| 25 |
yesthrow_t& operator=(yesthrow_t&&) noexcept(false) = default; |
| 26 |
}; |
| 27 |
|
| 28 |
static_assert(not is_nothrow_copy_constructible_v<yesthrow_t>, ""); |
| 29 |
static_assert(not is_nothrow_copy_assignable_v<yesthrow_t>, ""); |
| 30 |
static_assert(not is_nothrow_move_constructible_v<yesthrow_t>, ""); |
| 31 |
static_assert(not is_nothrow_move_assignable_v<yesthrow_t>, ""); |
| 32 |
|
| 33 |
// Note: by [meta.unary.prop] p9 this should be value-initialisation, |
| 34 |
// and thus by [dcl.init.general] p9 a trivial non-user-provided |
| 35 |
// non-deleted default constructor is not called. |
| 36 |
// However, CWG2820 proposes to change this behaviour. |
| 37 |
static_assert(is_nothrow_default_constructible_v<yesthrow_t>, ""); |
| 38 |
|
| 39 |
struct nothrow_t { |
| 40 |
nothrow_t() noexcept(true) = default; |
| 41 |
nothrow_t(const nothrow_t&) noexcept(true) = default; |
| 42 |
nothrow_t(nothrow_t&&) noexcept(true) = default; |
| 43 |
nothrow_t& operator=(const nothrow_t&) noexcept(true) = default; |
| 44 |
nothrow_t& operator=(nothrow_t&&) noexcept(true) = default; |
| 45 |
}; |
| 46 |
|
| 47 |
static_assert(is_nothrow_default_constructible_v<nothrow_t>, ""); |
| 48 |
static_assert(is_nothrow_copy_constructible_v<nothrow_t>, ""); |
| 49 |
static_assert(is_nothrow_copy_assignable_v<nothrow_t>, ""); |
| 50 |
static_assert(is_nothrow_move_constructible_v<nothrow_t>, ""); |
| 51 |
static_assert(is_nothrow_move_assignable_v<nothrow_t>, ""); |
| 52 |
|
| 53 |
struct A { A() noexcept(false) = default; }; |
| 54 |
struct B { B(const B&) noexcept(false) = default; }; |
| 55 |
struct C { C(C&&) noexcept(false) = default; }; |
| 56 |
struct D { D& operator=(const D&) noexcept(false) = default; }; |
| 57 |
struct E { E& operator=(E&&) noexcept(false) = default; }; |
| 58 |
|
| 59 |
static_assert(is_nothrow_default_constructible_v<A>, ""); // see above |
| 60 |
static_assert(not is_nothrow_copy_constructible_v<B>, ""); |
| 61 |
static_assert(not is_nothrow_move_constructible_v<C>, ""); |
| 62 |
static_assert(not is_nothrow_copy_assignable_v<D>, ""); |
| 63 |
static_assert(not is_nothrow_move_assignable_v<E>, ""); |
| 64 |
|