FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.abi / vtable.C
blob4c811a8c5abd37c65852db8ba29d28eb165ca3e4
1 // Test various aspects of vtable layout.
2 // Special g++ Options: -fno-strict-aliasing
3 // Origin: Mark Mitchell <mark@codesourcery.com>
5 #if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
7 struct S0
9   virtual void h ()
10   {
11   }
13   int k;
17 struct S1 
19   virtual void f () 
20   {
21   }
23   int i;
26 struct S2 : virtual public S0
28   virtual void g ()
29   {
30   }
32   int j;
35 struct S3 
37   virtual void k () 
38   {
39   }
41   int l;
44 struct S4 : public virtual S1, public S2, public S3
48 inline void* vtable (void *object)
50   // The vptr is always the first part of the object.
51   return * (void **) object;
54 int main ()
56   // The vtable layout order for S4 should consist of S4's primary
57   // vtable (shared with S2), followed by the vtable for S3 (because
58   // it is a non-virtual base).  Then, these should be followed by the
59   // the vtables for S1 and S0, which are virtual.
60   S4 s4;
61   S0 *s0 = &s4;
62   S1 *s1 = &s4;
63   S2 *s2 = &s4;
64   S3 *s3 = &s4;
65   
66   if (vtable (&s4) != vtable (s2))
67     return 1;
68   if (vtable (s2) >= vtable (s3))
69     return 2;
70   if (vtable (s3) >= vtable (s1))
71     return 3;
72   if (vtable (s1) >= vtable (s0))
73     return 4;
76 #else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
78 int main () 
82 #endif /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */