Debian Codegraph @

libstdc++-v3/testsuite/20_util/variant/102912.cc

raw
1 // { dg-do compile { target c++17 } }
2 #include <variant>
3
4 void
5 test01()
6 {
7 struct X {
8 ~X() { } // non-trivial
9 };
10
11 std::variant<const int, const X> v;
12 auto vv = v;
13 }
14
15 #if __cpp_lib_variant >= 202106L // P2231R1 constexpr destruction in variant
16 constexpr bool
17 test02()
18 {
19 struct Y {
20 constexpr ~Y() { } // non-trivial
21 };
22 using V = std::variant<int, const int, const Y, Y>;
23
24 V v1(std::in_place_index<1>, 1);
25 V vv1 = v1;
26 if (vv1.index() != v1.index())
27 return false;
28
29 V v2(std::in_place_index<2>);
30 V vv2 = v2;
31 if (vv2.index() != v2.index())
32 return false;
33
34 return true;
35 }
36 static_assert( test02() );
37
38 constexpr bool
39 test03()
40 {
41 struct Y {
42 constexpr ~Y() { } // non-trivial
43 };
44 using V = std::variant<int, int, Y, Y>;
45
46 V v1(std::in_place_index<1>, 1);
47 V vv1 = v1;
48 if (vv1.index() != v1.index())
49 return false;
50 vv1 = v1;
51 if (vv1.index() != v1.index())
52 return false;
53 vv1 = std::move(v1);
54 if (vv1.index() != v1.index())
55 return false;
56
57 V v2(std::in_place_index<2>);
58 V vv2 = v2;
59 if (vv2.index() != v2.index())
60 return false;
61 vv2 = v2;
62 if (vv2.index() != v2.index())
63 return false;
64 vv2 = std::move(v2);
65 if (vv2.index() != v2.index())
66 return false;
67
68 return true;
69 }
70 static_assert( test03() );
71 #endif