Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/noexcept81.C

raw
1 // { dg-do compile { target c++11 } }
2 // PR c++/96090
3
4 struct yesthrow_t {
5 yesthrow_t() noexcept(false) = default;
6 yesthrow_t(const yesthrow_t&) noexcept(false) = default;
7 yesthrow_t(yesthrow_t&&) noexcept(false) = default;
8 yesthrow_t& operator=(const yesthrow_t&) noexcept(false) = default;
9 yesthrow_t& operator=(yesthrow_t&&) noexcept(false) = default;
10 };
11
12 yesthrow_t yes;
13 static_assert(not noexcept(yesthrow_t(static_cast<const yesthrow_t&>(yes))), "");
14 static_assert(not noexcept(yesthrow_t(static_cast<yesthrow_t&&>(yes))), "");
15 static_assert(not noexcept(yes = static_cast<const yesthrow_t&>(yes)), "");
16 static_assert(not noexcept(yes = static_cast<yesthrow_t&&>(yes)), "");
17
18 // Note: this is value-initialisation, and thus by [dcl.init.general] p9
19 // a trivial non-user-provided non-deleted default constructor is not called.
20 // However, CWG2820 proposes to change this behaviour.
21 static_assert(noexcept(yesthrow_t()), "");
22
23 struct nothrow_t {
24 nothrow_t() noexcept(true) = default;
25 nothrow_t(const nothrow_t&) noexcept(true) = default;
26 nothrow_t(nothrow_t&&) noexcept(true) = default;
27 nothrow_t& operator=(const nothrow_t&) noexcept(true) = default;
28 nothrow_t& operator=(nothrow_t&&) noexcept(true) = default;
29 };
30
31 nothrow_t no;
32 static_assert(noexcept(nothrow_t()), "");
33 static_assert(noexcept(nothrow_t(static_cast<const nothrow_t&>(no))), "");
34 static_assert(noexcept(nothrow_t(static_cast<nothrow_t&&>(no))), "");
35 static_assert(noexcept(no = static_cast<const nothrow_t&>(no)), "");
36 static_assert(noexcept(no = static_cast<nothrow_t&&>(no)), "");
37