Debian Codegraph @

gcc/testsuite/g++.dg/expr/assign1.C

raw
1 // { dg-do run }
2
3 // Contributed by Nathan Sidwell 15 Dec 2003 <[email protected]>
4 // Origin: Tasso Karkanis <[email protected]>
5 // PR c++/13387. Clobbered tail padding of base
6
7 inline void *operator new (__SIZE_TYPE__, void *ptr)
8 {
9 return ptr;
10 }
11
12 struct Base {
13 Base() : i(0), c(0) {}
14 int i;
15 char c;
16 };
17
18 struct Sub : Base {
19 Sub () : d(0) {}
20 char d;
21 };
22
23 int main() {
24 Sub sub;
25 char base_alias[sizeof (Base)];
26 Base *base;
27
28 for (unsigned ix = sizeof base_alias; ix--;)
29 base_alias[ix] = 0x55;
30 base = new (&base_alias) Base ();
31
32 static_cast <Base &> (sub) = *base;
33 return sub.d;
34 }