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 NonPodNonPod19 NonPod () {m = 0x12345678;} NonPodNonPod20 NonPod (long m_) {m = m_;} 21 NonPod &operator= (NonPod const &src) {now = m; m = src.m; return *this;} NonPodNonPod22 NonPod (NonPod const &src) {m = src.m;} 23 }; 24 25 struct A : Inter 26 { AA27 A (long c) {m = c;} 28 29 NonPod m; 30 }; 31 32 struct B 33 { 34 Inter empty; 35 NonPod m; 36 BB37 B (long c) {m = c;} 38 }; 39 40 #if __cpp_attributes 41 struct B2 42 { 43 [[no_unique_address]] Inter empty; 44 NonPod m; 45 B2B246 B2 (long c) {m = c;} 47 }; 48 #endif 49 50 struct C : NonPod, Inter 51 { CC52 C (long c) : NonPod (c), Inter () {} 53 }; 54 main()55int main () 56 { 57 A a (0x12131415); 58 59 long was = a.m.m; 60 61 a = 0x22232425; 62 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 72 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; 87 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; 101 102 if (c.m.m != 0x22232425) 103 return 4; 104 } 105 #endif 106 107 C e (0x32333435); 108 109 if (e.m != 0x32333435) 110 return 2; // we copied padding 111 112 return 0; 113 } 114