Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/cond-triv1a.C

raw
1 // Like cond-triv1.C, but with the declaration order swapped.
2 // { dg-do compile { target concepts } }
3
4 #include <type_traits>
5
6 template <typename T>
7 class optional
8 {
9 struct empty {};
10 union {
11 empty _ = { };
12 T value;
13 };
14 bool engaged = false;
15
16 public:
17 constexpr optional() = default;
18
19 constexpr optional(optional const& o)
20 : engaged (o.engaged)
21 {
22 if (engaged)
23 new (&value) T (o.value);
24 }
25 constexpr optional(optional const&)
26 requires std::is_trivially_copy_constructible_v<T>
27 = default;
28
29 ~optional()
30 {
31 if (engaged)
32 value.~T();
33 }
34 ~optional()
35 requires std::is_trivially_destructible_v<T>
36 = default;
37
38 // ...
39 };
40
41 struct A { A(); A(const A&); ~A(); };
42
43 static_assert(std::is_trivially_copy_constructible_v<optional<int>>);
44 static_assert(!std::is_trivially_copy_constructible_v<optional<A>>);
45 static_assert(std::is_trivially_destructible_v<optional<int>>);
46 static_assert(!std::is_trivially_destructible_v<optional<A>>);