1 // Copyright (C) 2000 Free Software Foundation, Inc.
2 // Contributed by Nathan Sidwell 4 February 2001 <nathan@codesourcery.com>
4 // Check constructor vtables work. This is included from numerous test
5 // files, which set the #defines necessary to specify the hierarchy.
13 template <typename BASE, typename DERIVED>
14 int Test (DERIVED *d, int expect)
16 BASE *b = static_cast <BASE *> (d);
17 void *full_b = dynamic_cast <void *> (b);
18 void *full_d = dynamic_cast <void *> (d);
19 A *ap = static_cast <A *> (b);
24 fprintf (stderr, "base %s and derived %s have different full objects\n",
25 typeid (BASE).name (), typeid (DERIVED).name ());
29 DERIVED *dynamic_d = dynamic_cast <DERIVED *> (b);
34 fprintf (stderr, "dynamic_cast from %s to %s failed\n",
35 typeid (BASE).name (), typeid (DERIVED).name ());
39 b->Baz (static_cast <void *> (ap));
41 int res = b->Foo (static_cast <void *> (d));
46 fprintf (stderr, "%s::Foo returned %d, expected %d\n",
47 typeid (BASE).name (), res, expect);
55 int Test (T *self, void *expected, int result)
60 fprintf (stderr, "%s::Foo wrong this pointer\n", typeid (T).name ());
69 virtual int Foo (void *p) {return Test (this, p, 1);}
70 virtual int Baz (void *p) {return Test (this, p, 1);}
75 struct B1: virtual A {
79 virtual int Foo (void *p) {return Test (this, p, 2);}
84 struct B2: virtual A {
88 virtual int Foo (void *p) {return Test (this, p, 3);}
95 struct C : C_PARENTS {
99 virtual int Foo (void *p) {return Test (this, p, 4);}
106 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
111 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
117 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
123 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
129 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
135 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
141 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
147 fprintf (stderr, "%s\n", __PRETTY_FUNCTION__);
153 struct D1 : virtual C {};
154 struct D2 : virtual A, virtual C {};
159 fprintf (stderr, "C\n");
163 fprintf (stderr, "D\n");
167 fprintf (stderr, "D1\n");
171 fprintf (stderr, "D2\n");
175 fprintf (stderr, "There are %d failings\n", fail);
177 fprintf (stderr, "Passed\n");