aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor18.C
blob: dc0d174b474434366decb53e35b31469ce9b133b (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
// PR c++/121068
// { dg-do compile { target c++20 } }

template <class T>
constexpr void
destroy_at (T* p) { p->~T(); }

template <class T>
struct V {
  union {
    unsigned char buf[sizeof (T)];
    const T ct;
  };
  bool active;
  constexpr V(): active (false) {}
  constexpr V(T t): ct (t), active (true) { }
  constexpr ~V() { if (active) destroy_at (&ct); }
};

constexpr char f()
{
  const V<int> vi {42};
  return vi.ct;
}

static_assert (f() == 42);