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