aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/is_nothrow_constructible8.C
blob: 996f6d895ffb62bad9b2668074fcdea7a6265737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// { dg-do compile { target c++14 } }
// PR c++/96090

template <typename T>
constexpr bool is_nothrow_default_constructible_v
  = __is_nothrow_constructible(T);
template <typename T>
constexpr bool is_nothrow_copy_constructible_v
  = __is_nothrow_constructible(T, const T&);
template <typename T>
constexpr bool is_nothrow_move_constructible_v
  = __is_nothrow_constructible(T, T&&);
template <typename T>
constexpr bool is_nothrow_copy_assignable_v
  = __is_nothrow_assignable(T, const T&);
template <typename T>
constexpr bool is_nothrow_move_assignable_v
  = __is_nothrow_assignable(T, T&&);

struct yesthrow_t {
  yesthrow_t()                              noexcept(false) = default;
  yesthrow_t(const yesthrow_t&)             noexcept(false) = default;
  yesthrow_t(yesthrow_t&&)                  noexcept(false) = default;
  yesthrow_t& operator=(const yesthrow_t&)  noexcept(false) = default;
  yesthrow_t& operator=(yesthrow_t&&)       noexcept(false) = default;
};

static_assert(not is_nothrow_copy_constructible_v<yesthrow_t>, "");
static_assert(not is_nothrow_copy_assignable_v<yesthrow_t>, "");
static_assert(not is_nothrow_move_constructible_v<yesthrow_t>, "");
static_assert(not is_nothrow_move_assignable_v<yesthrow_t>, "");

// Note: by [meta.unary.prop] p9 this should be value-initialisation,
// and thus by [dcl.init.general] p9 a trivial non-user-provided
// non-deleted default constructor is not called.
// However, CWG2820 proposes to change this behaviour.
static_assert(is_nothrow_default_constructible_v<yesthrow_t>, "");

struct nothrow_t {
  nothrow_t()                             noexcept(true) = default;
  nothrow_t(const nothrow_t&)             noexcept(true) = default;
  nothrow_t(nothrow_t&&)                  noexcept(true) = default;
  nothrow_t& operator=(const nothrow_t&)  noexcept(true) = default;
  nothrow_t& operator=(nothrow_t&&)       noexcept(true) = default;
};

static_assert(is_nothrow_default_constructible_v<nothrow_t>, "");
static_assert(is_nothrow_copy_constructible_v<nothrow_t>, "");
static_assert(is_nothrow_copy_assignable_v<nothrow_t>, "");
static_assert(is_nothrow_move_constructible_v<nothrow_t>, "");
static_assert(is_nothrow_move_assignable_v<nothrow_t>, "");

struct A { A() noexcept(false) = default; };
struct B { B(const B&) noexcept(false) = default; };
struct C { C(C&&) noexcept(false) = default; };
struct D { D& operator=(const D&) noexcept(false) = default; };
struct E { E& operator=(E&&) noexcept(false) = default; };

static_assert(is_nothrow_default_constructible_v<A>, "");  // see above
static_assert(not is_nothrow_copy_constructible_v<B>, "");
static_assert(not is_nothrow_move_constructible_v<C>, "");
static_assert(not is_nothrow_copy_assignable_v<D>, "");
static_assert(not is_nothrow_move_assignable_v<E>, "");