OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [gcc/] [testsuite/] [g++.old-deja/] [g++.other/] [rttid3.C] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 305 jeremybenn
// { dg-do run  }
2
// { dg-options "-frtti" }
3
// test of rtti of single inheritance and multiple inheritance with
4
// virtual functions
5
// dynamic casting
6
 
7
#include 
8
 
9
extern "C" {
10
  int printf(const char *, ...);
11
  void exit(int);
12
}
13
 
14
class X {
15
 public:
16
  int xi;
17
  virtual int f() {return 0;};
18
};
19
 
20
class Y : public X {
21
  short ys;
22
};
23
 
24
class Z : public Y {
25
  int zi;
26
};
27
 
28
Z z;
29
Y y;
30
Y *yp = &z;
31
X *xp = &z;
32
Z *zp = &z;
33
 
34
class A {
35
 public:
36
  int Ai;
37
  virtual int a() {return 0;};
38
};
39
 
40
class B {
41
 public:
42
  int Bi;
43
  virtual int g() {return 0;};
44
};
45
 
46
class D : public A, public B {
47
  int Di;
48
};
49
 
50
/*
51
class E : public D, public B {
52
  int Ei;
53
};
54
*/
55
class E {
56
  int Ei;
57
};
58
 
59
class F : public E, public D {
60
  int Fi;
61
};
62
 
63
D d;
64
A *ap = &d;
65
B *bp = &d;
66
D *dp = &d;
67
F f;
68
F *fp = &f;
69
A *aap = &f;
70
B *bbp = &f;
71
 
72
void *vp = zp;
73
 
74
/*
75
void error (int i)
76
{
77
  printf("FAIL\n");
78
  exit(i);
79
}
80
*/
81
 
82
void error  (int i)
83
{
84
  exit(i);
85
}
86
 
87
int main ()
88
{
89
  vp = (void *)0;
90
 
91
  vp = dynamic_cast (&z);
92
  if (vp == 0) error(11);
93
 
94
  vp = dynamic_cast (yp);
95
  if (vp == 0) error(11);
96
 
97
  vp = dynamic_cast (yp);
98
  if (vp == 0) error(12);
99
 
100
  vp = dynamic_cast (dp);
101
  if (vp != (void *)dp) error(21);
102
 
103
  vp = dynamic_cast (dp);
104
  if (vp == (void *)dp) error(21);
105
 
106
  vp = dynamic_cast (fp);
107
  if (vp != (void *)bbp) error(22);
108
 
109
  vp = dynamic_cast (aap);
110
  if (vp != (void *)fp) error(23);
111
 
112
  vp = dynamic_cast (aap);
113
  if (vp != (void *)bbp) error(24);
114
 
115
}
116
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.