OSDN Git Service

Rework build_component_ref.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / abi / empty4.C
1 // { dg-do run }
2
3 // Copyright (C) 2001 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 31 Jul 2001 <nathan@codesourcery.com>
5
6 // Bug 3820. We were bit copying empty bases including the
7 // padding. Which clobbers whatever they overlay.
8
9 struct Empty {};
10
11 struct Inter : Empty {};
12
13 long now = 0;
14
15 struct NonPod
16 {
17   long m;
18
19   NonPod () {m = 0x12345678;}
20   NonPod (long m_) {m = m_;}
21   NonPod &operator= (NonPod const &src) {now = m; m = src.m; return *this;}
22   NonPod (NonPod const &src) {m = src.m;}
23 };
24
25 struct A : Inter
26 {
27   A (long c) {m = c;}
28   
29   NonPod m;
30 };
31
32 struct B
33 {
34   Inter empty;
35   NonPod m;
36
37   B (long c) {m = c;}
38 };
39
40 struct C : NonPod, Inter
41 {
42   C (long c) : NonPod (c), Inter () {}
43 };
44
45 int main ()
46 {
47   A a (0x12131415);
48   
49   long was = a.m.m;
50   
51   a = 0x22232425;
52
53   if (was != now)
54     return 1;   // we copied the empty base which clobbered a.m.m's
55                 // original value.
56   
57   A b (0x32333435);
58   *(Inter *)&a = *(Inter *)&b;
59   
60   if (a.m.m != 0x22232425)
61     return 2;   // we copied padding, which clobbered a.m.m
62
63   A b2 (0x32333435);
64   (Inter &)b2 = Inter ();
65   if (b2.m.m != 0x32333435)
66     return 2;   // we copied padding, which clobbered b2.m.m
67   
68   B c (0x12131415);
69   was = c.m.m;
70   c = 0x22232425;
71   if (was != now)
72     return 3;
73   
74   B d (0x32333435);
75   c.empty = d.empty;
76
77   if (c.m.m != 0x22232425)
78     return 4;
79
80   C e (0x32333435);
81
82   if (e.m != 0x32333435)
83     return 2;   // we copied padding
84   
85   return 0;
86 }