aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic12.C
blob: 4aedf9893ada4c67a056390c50435029cd786ef1 (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
// PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr.
// { dg-do compile { target c++20 } }

// dynamic_cast in a destructor.

struct A2 { virtual void a2(); };

struct A : A2 { virtual void a(); };

struct C2 { virtual void c2(); };

struct B : A, C2 {
  constexpr ~B();
};

constexpr B::~B()
{
  A *a = dynamic_cast<A*>((C2*)this);
  if (a != (A*) this)
    __builtin_abort ();
  A& ar = dynamic_cast<A&>((C2&)*this);
  if (&ar != &(A&)*this)
    __builtin_abort ();
}

struct D : B { virtual void d(); };

constexpr D d;