Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic16.C

raw
1 // PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr.
2 // { dg-do compile { target c++20 } }
3 // Here the hint turns out to be wrong: A is a public base of B2, but the
4 // dynamic_cast operand is not that subobject, but rather a sibling base of
5 // B2.
6
7 struct A { virtual void f(); };
8 struct B1: A { };
9 struct B2: A { };
10 struct C: B1, B2 { };
11
12 constexpr C c;
13 constexpr A *ap = (B1*)&c;
14 constexpr A &ar = (B1&)c;
15 constexpr auto p = dynamic_cast<B2*>(ap);
16 static_assert (p != nullptr);
17 constexpr auto p2 = dynamic_cast<B2&>(ar);
18 static_assert(dynamic_cast<B2*>(ap) == (B2*)&c);
19 static_assert(dynamic_cast<B2*>((B1*)&c) == (B2*)&c);
20 static_assert(&dynamic_cast<B2&>((B1&)c) == &(B2&)c);