summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.other/dyncast6.C
blob: 52b57e544cc2bb0c9800fb1ecaa91949504647e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// { dg-do run  }
// { dg-options "-w -ansi -pedantic-errors" }

// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 20 June 2000 <nathan@codesourcery.com>

// Origin GNATS bug report 143 from Carlo Wood <carlo@runaway.xs4all.nl>
// We were generating incorrect type_info structures, and hence breaking
// dynamic_cast.

#include <stdio.h>

class OBASE { public: virtual void bz () {}};
class IBASE { public: virtual void by () {}};

class V {public:int m; };

class A : public virtual V { };
class AA : public A {};

class B : public OBASE, public A { public: virtual void foo(void) { } };
class B1 : public OBASE, public AA { public: virtual void foo(void) { } };

class C : public IBASE, public virtual V { };

class D : public B, public C { };

class E : public B, public virtual V { };

class E1 : public B1, public virtual V {};

class E2 : public B1, public A, public virtual V {};

int main(void)
{
  D d;
  E e;
  E1 e1;
  E2 e2;
  int code = 0;

  OBASE* osd = &d;
  OBASE* ose = &e;
  OBASE* ose1 = &e1;
  OBASE* ose2 = &e2;


  if (!dynamic_cast<V*>(osd))
    {
      printf ("fail osd\n");
      code++;
    }
  
  if (!dynamic_cast<V*>(ose))
    {
      printf ("fail ose\n");
      code++;
    }

  if (!dynamic_cast<V*>(ose1))
    {
      printf ("fail ose1\n");
      code++;
    }

  if (!dynamic_cast<V*>(ose2))
    {
      printf ("fail ose2\n");
      code++;
    }

  return code;
}