aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/variant/102912.cc
blob: 0dea138c5ba153bcf8422270dda1aa8a57723e75 (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
65
66
67
68
69
70
71
// { dg-do compile { target c++17 } }
#include <variant>

void
test01()
{
  struct X {
    ~X() { } // non-trivial
  };

  std::variant<const int, const X> v;
  auto vv = v;
}

#if __cpp_lib_variant >= 202106L // P2231R1 constexpr destruction in variant
constexpr bool
test02()
{
  struct Y {
    constexpr ~Y() { } // non-trivial
  };
  using V = std::variant<int, const int, const Y, Y>;

  V v1(std::in_place_index<1>, 1);
  V vv1 = v1;
  if (vv1.index() != v1.index())
    return false;

  V v2(std::in_place_index<2>);
  V vv2 = v2;
  if (vv2.index() != v2.index())
    return false;

  return true;
}
static_assert( test02() );

constexpr bool
test03()
{
  struct Y {
    constexpr ~Y() { } // non-trivial
  };
  using V = std::variant<int, int, Y, Y>;

  V v1(std::in_place_index<1>, 1);
  V vv1 = v1;
  if (vv1.index() != v1.index())
    return false;
  vv1 = v1;
  if (vv1.index() != v1.index())
    return false;
  vv1 = std::move(v1);
  if (vv1.index() != v1.index())
    return false;

  V v2(std::in_place_index<2>);
  V vv2 = v2;
  if (vv2.index() != v2.index())
    return false;
  vv2 = v2;
  if (vv2.index() != v2.index())
    return false;
  vv2 = std::move(v2);
  if (vv2.index() != v2.index())
    return false;

  return true;
}
static_assert( test03() );
#endif