Enable flate-combine.
[official-gcc.git] / gcc / testsuite / g++.dg / abi / empty4.C
blob8cc10a9fb0f42e5897e190b31a5f6cd9cb59b67e
1 // { dg-do run }
3 // Copyright (C) 2001 Free Software Foundation, Inc.
4 // Contributed by Nathan Sidwell 31 Jul 2001 <nathan@codesourcery.com>
6 // Bug 3820. We were bit copying empty bases including the
7 // padding. Which clobbers whatever they overlay.
9 struct Empty {};
11 struct Inter : Empty {};
13 long now = 0;
15 struct NonPod
17   long m;
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;}
25 struct A : Inter
27   A (long c) {m = c;}
28   
29   NonPod m;
32 struct B
34   Inter empty;
35   NonPod m;
37   B (long c) {m = c;}
40 #if __cpp_attributes
41 struct B2
43   [[no_unique_address]] Inter empty;
44   NonPod m;
46   B2 (long c) {m = c;}
48 #endif
50 struct C : NonPod, Inter
52   C (long c) : NonPod (c), Inter () {}
55 int main ()
57   A a (0x12131415);
58   
59   long was = a.m.m;
60   
61   a = 0x22232425;
63   if (was != now)
64     return 1;   // we copied the empty base which clobbered a.m.m's
65                 // original value.
66   
67   A b (0x32333435);
68   *(Inter *)&a = *(Inter *)&b;
69   
70   if (a.m.m != 0x22232425)
71     return 2;   // we copied padding, which clobbered a.m.m
73   A b2 (0x32333435);
74   (Inter &)b2 = Inter ();
75   if (b2.m.m != 0x32333435)
76     return 2;   // we copied padding, which clobbered b2.m.m
77   
78   {
79   B c (0x12131415);
80   was = c.m.m;
81   c = 0x22232425;
82   if (was != now)
83     return 3;
84   
85   B d (0x32333435);
86   c.empty = d.empty;
88   if (c.m.m != 0x22232425)
89     return 4;
90   }
91 #if __cpp_attributes
92   {
93   B2 c (0x12131415);
94   was = c.m.m;
95   c = 0x22232425;
96   if (was != now)
97     return 3;
98   
99   B2 d (0x32333435);
100   c.empty = d.empty;
102   if (c.m.m != 0x22232425)
103     return 4;
104   }    
105 #endif
107   C e (0x32333435);
109   if (e.m != 0x32333435)
110     return 2;   // we copied padding
111   
112   return 0;