Mercurial > hg > CbC > CbC_gcc
diff gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic1.C @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic1.C Thu Feb 13 11:34:05 2020 +0900 @@ -0,0 +1,40 @@ +// PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr. +// { dg-do compile { target c++2a } } + +// Downcast. + +struct B { + virtual void baz () {} +}; + +struct D : B { }; + +constexpr bool +fn () +{ + bool ok = true; + B b; + B *b1 = &b; + if (D *pd = dynamic_cast<D*>(b1)) + ok = false; + + D d; + B *b2 = &d; + if (D *pd = dynamic_cast<D*>(b2)) + /*OK*/; + else + ok = false; + + return ok; +} + +static_assert(fn ()); + +constexpr D d; +constexpr B b; +constexpr B *b1 = const_cast<B*>(&b); +constexpr B *b2 = const_cast<D*>(&d); +static_assert(dynamic_cast<D*>(b2) == &d); +static_assert(&dynamic_cast<D&>(*b2) == &d); +static_assert(dynamic_cast<const B*>(&d) == &d); +static_assert(&dynamic_cast<const B&>(d) == &d);