]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/casts.cc
Fix C++ cast of derived class to base class
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / casts.cc
1 struct A
2 {
3 int a;
4 A (int aa): a (aa) {}
5 };
6
7 struct B: public A
8 {
9 int b;
10 B (int aa, int bb): A (aa), b(bb) {}
11 };
12
13
14 struct Alpha
15 {
16 virtual void x() { }
17 };
18
19 struct Gamma
20 {
21 };
22
23 struct Derived : public Alpha
24 {
25 };
26
27 struct VirtuallyDerived : public virtual Alpha
28 {
29 };
30
31 struct DoublyDerived : public VirtuallyDerived,
32 public virtual Alpha,
33 public Gamma
34 {
35 };
36
37 struct Left
38 {
39 int left;
40 };
41
42 struct Right
43 {
44 int right;
45 };
46
47 struct LeftRight : public Left, public Right
48 {
49 };
50
51 int
52 main (int argc, char **argv)
53 {
54 A *a = new B(42, 1729);
55 B *b = (B *) a;
56 A &ar = *b;
57 B &br = (B&)ar;
58
59 Derived derived;
60 DoublyDerived doublyderived;
61
62 Alpha *ad = &derived;
63 Alpha *add = &doublyderived;
64
65 LeftRight gd;
66 gd.left = 23;
67 gd.right = 27;
68 unsigned long long gd_value = (unsigned long long) &gd;
69 unsigned long long r_value = (unsigned long long) (Right *) &gd;
70
71 return 0; /* breakpoint spot: casts.exp: 1 */
72 }