comparison gcc/testsuite/g++.dg/cpp2a/cond-triv1a.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
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>>);