xref: /openbsd-src/gnu/usr.bin/gcc/gcc/testsuite/g++.old-deja/g++.abi/primary.C (revision c87b03e512fc05ed6e0222f6fb0ae86264b1d05b)
1 // Test to see that primary bases are selected correctly.
2 // Origin: Mark Mitchell <mark@codesourcery.com>
3 
4 #if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
5 
6 // S1 is a nearly-empty base.
7 
8 struct S1
9 {
fS110   virtual void f ()
11   {
12   }
13 };
14 
15 // S2 is a dynamic, but not nearly-empty, base.
16 
17 struct S2
18 {
gS219   virtual void g ()
20   {
21   }
22 
23   int i;
24 };
25 
26 // S1 should be the primary base.
27 
28 struct T1 : public S1, public S2
29 {
30 };
31 
32 // S2 should be the primary base.
33 
34 struct T2 : public S2, public S1
35 {
36 };
37 
38 // S2 should be the primary base.
39 
40 struct T3 : virtual public S1, public S2
41 {
42 };
43 
44 // S1 should be the primary base.
45 
46 struct T4 : virtual public S1, virtual public S2
47 {
48 };
49 
50 // Check that Y is the primary base for X.  Otherwise, return N.
51 #define CHECK_PRIMARY_BASE(X, Y, N)		\
52   {						\
53     X x;					\
54     if ((void*) &x != (void *) (Y*) (&x))	\
55       return N;					\
56   }
57 
main()58 int main ()
59 {
60   CHECK_PRIMARY_BASE (T1, S1, 1);
61   CHECK_PRIMARY_BASE (T2, S2, 2);
62   CHECK_PRIMARY_BASE (T3, S2, 3);
63   CHECK_PRIMARY_BASE (T4, S1, 4);
64 }
65 
66 #else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
67 
main()68 int main ()
69 {
70 }
71 
72 #endif /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
73