summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/expr/assign1.C
blob: 7eb37e523acaa9b6f239af9048adfb1a3b10fb84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// { dg-do run }

// Contributed by Nathan Sidwell 15 Dec 2003 <nathan@codesourcery.com>
// Origin: Tasso Karkanis <Tasso.Karkanis@rogers.com>
// PR c++/13387. Clobbered tail padding of base

inline void *operator new (__SIZE_TYPE__, void *ptr) 
{
  return ptr;
}

struct Base { 
    Base() : i(0), c(0) {} 
    int i; 
    char c; 
}; 
 
struct Sub : Base { 
    Sub () : d(0) {} 
    char d; 
}; 
 
int main() { 
  Sub sub;
  char base_alias[sizeof (Base)];
  Base *base;
  
  for (unsigned ix = sizeof base_alias; ix--;)
    base_alias[ix] = 0x55;
  base = new (&base_alias) Base ();
  
  static_cast <Base &> (sub) = *base;
  return sub.d; 
}