Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.mike/dyncast7.C

raw
1 // { dg-do run }
2 // { dg-options "-fexceptions" }
3 // { dg-skip-if "requires hosted libstdc++ for stdexcept" { ! hostedlib } }
4
5 #include <typeinfo>
6 #include <stdexcept>
7
8 class A {
9 public:
10 virtual void j () {}
11 };
12
13 class B : public A { };
14
15 void x (A& a) {
16 // These should all work.
17 const B& b2 = dynamic_cast<B&>(a);
18 const B& b3 = dynamic_cast<const B&>((const A&)a);
19 const B& b4 = dynamic_cast<const B&>(a);
20 }
21
22 int main() {
23 try {
24 B b;
25 x (b);
26 } catch (std::exception& e) {
27 // If we get a bad_cast, it is wrong.
28 return 1;
29 }
30 }