File: 102912.cc

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (71 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download | duplicates (2)
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